From owner-sc22wg5+sc22wg5-dom8=www.open-std.org@open-std.org Thu Sep 28 21:07:09 2017 Return-Path: X-Original-To: sc22wg5-dom8 Delivered-To: sc22wg5-dom8@www.open-std.org Received: by www.open-std.org (Postfix, from userid 521) id 20D77358929; Thu, 28 Sep 2017 21:07:08 +0200 (CEST) Delivered-To: sc22wg5@open-std.org X-Greylist: delayed 582 seconds by postgrey-1.34 at www5.open-std.org; Thu, 28 Sep 2017 21:07:08 CEST Received: from math.jpl.nasa.gov (unknown [137.79.7.57]) by www.open-std.org (Postfix) with ESMTP id 507C73585C0 for ; Thu, 28 Sep 2017 21:07:07 +0200 (CEST) Received: by math.jpl.nasa.gov (Postfix, from userid 3593) id C2B5C33DA7C; Thu, 28 Sep 2017 11:57:22 -0700 (PDT) Subject: Re: (j3.2006) (SC22WG5.5979) Generic programming examples From: Van Snyder To: sc22wg5 In-Reply-To: References: <20170927201113.6D137358742@www.open-std.org> <20170928020816.B2E4D358742@www.open-std.org> <20170928123430.2C442358929@www.open-std.org> <20170928161910.0439E358A27@www.open-std.org> Content-Type: multipart/alternative; boundary="=-v47M449hhpk4nRSFjytj" Date: Thu, 28 Sep 2017 11:57:22 -0700 Message-ID: <1506625042.32527.321.camel@math.jpl.nasa.gov> Mime-Version: 1.0 X-Mailer: Evolution 2.32.3 (2.32.3-37.el6) Sender: owner-sc22wg5@open-std.org Precedence: bulk --=-v47M449hhpk4nRSFjytj Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, 2017-09-28 at 10:37 -0700, Damian Rouson wrote: >=20 >=20 >=20 >=20 > On September 28, 2017 at 9:19:14 AM, Bill Long (longb@cray.com) wrote: >=20 >=20 > >=20 > >=20 > > > On Sep 28, 2017, at 7:34 AM, Clune, Thomas L. (GSFC-6101) > > wrote:=20 > > >=20 > > > Sorry - not sure how my subconscious injected the word > > =E2=80=9Cexceptions=E2=80=9D below. I meant =E2=80=9CUsing generics/tem= plates should not > > make us lose this other [type-bound procedures] capability.=E2=80=9D= =20 > > >=20 > >=20 > > Makes more sense now.=20 > >=20 > > A type bound procedure referenced though a polymorphic variable > > cannot itself be a template because the compiler does not know what > > procedure is being called at compile time. However, inside the > > specific TBP, you can call worker routines that do the actual work, > > and those can be written as templates if that would be useful. There > > is a (probably small) performance hit for the second call, but you > > are already making an anti-performance decision by using the TBP > > path in the first place. Whether this matters that much depends on > > how you decide to organize the code.=20 >=20 > I suspect that these are some of the reasons that many in the C++ > community are moving away from runtime polymorphism and inheritance > and migrating more toward compile-time polymorphism and templates. > Partly for this reason, I=E2=80=99ve been hoping to get one collaborator = to > join J3/WG5 who specializes in language design, has some experience on > the C++ committee, has an interest in modern Fortran, and was one of > the first people to mention the aforementioned trend in C++ > programming practices. What Bill describes above might be a good > compromise between the two programming styles. I=E2=80=99m not surprised > there=E2=80=99s some tension between the two. As far as I know, Ada didn't have the same kinds of growing pains with generic packages that C++ had with templates, or the same problems with the relationship of polymorphism to generic packages that C++ had between polymorphism and templates. Should we really be trying to copy a C++ kludge when we have an Ada example that worked just fine right out of the box? --=-v47M449hhpk4nRSFjytj Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable On Thu, 2017-09-28 at 10:37 -0700, Damian Rouson wrote:



On September 28, 2017 at 9:19:14 AM, Bill Long (longb@cray.com) wrote:



> On Sep 28, 2017, at 7:34 AM, Clune, Thomas L. (GSFC-6101) <= thomas.l.clune@nasa.gov> wrote: 

> Sorry - not sure how my subconscious injected the word “= exceptions” below. I meant “Using generics/templates should not= make us lose this other [type-bound procedures] capability.” 

Makes more sense now. 

A type bound procedure referenced though a polymorphic variable can= not itself be a template because the compiler does not know what procedure = is being called at compile time. However, inside the specific TBP, you can = call worker routines that do the actual work, and those can be written as t= emplates if that would be useful. There is a (probably small) performance h= it for the second call, but you are already making an anti-performance deci= sion by using the TBP path in the first place. Whether this matters that mu= ch depends on how you decide to organize the code. 
I suspect that these are some of the reasons that many in the C++ commu= nity are moving away from runtime polymorphism and inheritance and migratin= g more toward compile-time polymorphism and templates.  Partly for thi= s reason, I’ve been hoping to get one collaborator to join J3/WG5 who= specializes in language design, has some experience on the C++ committee, = has an interest in modern Fortran, and was one of the first people to menti= on the aforementioned trend in C++ programming practices.  What Bill d= escribes above might be a good compromise between the two programming style= s. I’m not surprised there’s some tension between the two.

As far as I know, Ada didn't have the same kinds of growing pains with gene= ric packages that C++ had with templates, or the same problems with the rel= ationship of polymorphism to generic packages that C++ had between polymorp= hism and templates.  Should we really be trying to copy a C++ kludge w= hen we have an Ada example that worked just fine right out of the box?

--=-v47M449hhpk4nRSFjytj--