Prev: Ada 2012: An Oops in the new Ada amendments ? (in 10.1.2 ContextClauses - With Clauses)
Next: Ada 2012: An Oops in the new Ada amendments ? (in 10.1.2 Context Clauses - With Clauses)
From: sjw on 12 Aug 2010 08:48 On Aug 12, 11:36 am, Stephen Leake <stephen_le...(a)stephe-leake.org> wrote: > Post complete code, I'll try it on my version of gnat. Thanks. Remember -gnatpg! The code I posted above is the complete spec (not going to bother to write the body if can't get the spec to compile!): with Ada.Numerics.Generic_Complex_Arrays; with Ada.Numerics.Generic_Complex_Types; generic with package Complex_Types is new Ada.Numerics.Generic_Complex_Types (Real); with package Complex_Arrays is new Ada.Numerics.Generic_Complex_Arrays (Generic_Real_Arrays, Complex_Types); -- <<<<<<<<<<<<<<<<<< use Complex_Arrays; package Ada.Numerics.Generic_Real_Arrays.Extensions is function Eigenvalues (A : Real_Matrix) return Complex_Vector; end Ada.Numerics.Generic_Real_Arrays.Extensions;
From: Simon Wright on 12 Aug 2010 15:45 "Dmitry A. Kazakov" <mailbox(a)dmitry-kazakov.de> writes: > Further I would name it > > generic > package Ada.Numerics.Generic_Complex_Arrays. > Generic_Real_Extensions; > ^^^^ > or Generic_Real_Valued_Extensions; > ^^^^^ > > It is always helpful to keep all name spaces clean of generic names. Not quite sure what you mean here? I think you're recommending that all names of generic units should include an indication that they're generic, so that people don't get confused as to generic vs instantiation? In other places I've tacked _G on the end of the 'obvious' name: generic package ColdFrame.Events_G.Standard_G.Callback_Manager_G is and I saw someone else (Ludovic?) doing the same here recently. I think that people are going to get confused instantiating children of generic packages, and that there's nothing like a helpful example to clarify. Currently I have (with elsewhere, "type Real is digits <>;") package Real_Arrays is new Ada.Numerics.Generic_Real_Arrays (Real); package Complex_Types is new Ada.Numerics.Generic_Complex_Types (Real); package Complex_Arrays is new Ada.Numerics.Generic_Complex_Arrays (Real_Arrays, Complex_Types); package Extensions is new Complex_Arrays.Extensions; Do people feel this would be clearer if the last 2 lines read instead package Extensions is new Complex_Arrays.Generic_Extensions; (and if so, how much clearer?!)
From: Dmitry A. Kazakov on 13 Aug 2010 02:27 On Thu, 12 Aug 2010 20:45:33 +0100, Simon Wright wrote: > "Dmitry A. Kazakov" <mailbox(a)dmitry-kazakov.de> writes: > >> Further I would name it >> >> generic >> package Ada.Numerics.Generic_Complex_Arrays. >> Generic_Real_Extensions; >> ^^^^ >> or Generic_Real_Valued_Extensions; >> ^^^^^ >> >> It is always helpful to keep all name spaces clean of generic names. > > Not quite sure what you mean here? > > I think you're recommending that all names of generic units should > include an indication that they're generic, so that people don't get > confused as to generic vs instantiation? More important is that names of generics do not hide other names. Sooner or later it becomes a problem. > In other places I've tacked _G on the end of the 'obvious' name: > > generic > package ColdFrame.Events_G.Standard_G.Callback_Manager_G is > > and I saw someone else (Ludovic?) doing the same here recently. I used plural suffix 's' before, but it Generic is clearer and it seems like a semi-standard now. > I think that people are going to get confused instantiating children of > generic packages, and that there's nothing like a helpful example to > clarify. > > Currently I have (with elsewhere, "type Real is digits <>;") > > package Real_Arrays > is new Ada.Numerics.Generic_Real_Arrays (Real); > package Complex_Types > is new Ada.Numerics.Generic_Complex_Types (Real); > package Complex_Arrays > is new Ada.Numerics.Generic_Complex_Arrays (Real_Arrays, Complex_Types); > package Extensions > is new Complex_Arrays.Extensions; > > Do people feel this would be clearer if the last 2 lines read instead > > package Extensions > is new Complex_Arrays.Generic_Extensions; > > (and if so, how much clearer?!) Yes, especially because of two "Extensions". I had immense problems with names. Look at this: http://www.dmitry-kazakov.de/ada/fuzzy_packages.gif Somewhere down deep the hierarchy the user starts to become incomprehensive error messages upon instantiation within the generic(!) bodies. It is practically impossible to understand what is wrong, is it a compiler bug (in GNAT case) or something else. For the user it would be a nightmare to fight this. Another rule of thumb (I don't know if this is going to be fixed in Ada 2012), is that a child should always rename formal generic arguments in its specifications. Under certain circumstances, usually in children, they might become unavailable. I mean this: generic with package P is new Generic_P (<>); package Generic_S is package P_Of renames P; -- You will need this! Sometimes you need to "rename" formal types as well: generic type Foo is ... package Generic_S is subtype Foo_Of is Foo; -- What a mess! -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de
From: Ludovic Brenta on 13 Aug 2010 02:54 "Dmitry A. Kazakov" <mailbox(a)dmitry-kazakov.de> writes: >> In other places I've tacked _G on the end of the 'obvious' name: >> >> generic >> package ColdFrame.Events_G.Standard_G.Callback_Manager_G is >> >> and I saw someone else (Ludovic?) doing the same here recently. > > I used plural suffix 's' before, but it Generic is clearer and it seems > like a semi-standard now. Yes, I did a _G here recently; I let the coding standard of Eurocontrol (my day job) influence me. The coding standard says *_G for generics, *_T for secondary types and just T for types. Hence: package S_Expression is -- singlular type T is ...; -- the primary type, S_Expression.T generic ... package Serialization_G is ... end Serialization_G; private type Internal_T is ...; -- a secondary (helper) type end S_Expression; Over the years I grew used to it and now I like it. One of the advantages is that you don't have to struggle to find meaningful names for parameters; e.g. you can say: procedure Foo (Internal : out Internal_T) is ... end Foo; -- Ludovic Brenta.
From: Georg Bauhaus on 13 Aug 2010 03:42
On 8/13/10 8:27 AM, Dmitry A. Kazakov wrote: > Another rule of thumb (I don't know if this is going to be fixed in Ada > 2012), is that a child should always rename formal generic arguments in its > specifications. Under certain circumstances, usually in children, they > might become unavailable. I mean this: Would you mind showing an example of a name that is needed but unavailable? > generic > with package P is new Generic_P (<>); > package Generic_S is > package P_Of renames P; -- You will need this! |