From: Jere <jhb.chat@gmail.com>
Subject: Re: Tagged type naming convention
Date: Mon, 6 Nov 2017 16:43:01 -0800 (PST)
Date: 2017-11-06T16:43:01-08:00 [thread overview]
Message-ID: <2d066e87-8cf3-430d-b18f-9c834afe499d@googlegroups.com> (raw)
In-Reply-To: <87y3nkft3n.fsf@jacob-sparre.dk>
On Sunday, November 5, 2017 at 2:01:02 PM UTC-5, Jacob Sparre Andersen wrote:
> Jere writes:
>
> > I was looking at an older document for a naming convention for tagged
> > types and stumbled upon J.P. Rosen's "A Naming Convention for Classes
> > in Ada 9X" [1]. It's pretty intriguing and, even though it was
> > developed for 9X, it has applicability in the current Ada revision.
> > However, I haven't really seen it employed in any of the libraries
> > I've messed with. Keep in mind, my experience with external libraries
> > is limited. I was curious if this style is something that a lot of
> > people use and had some input on. Is it still in use? Pros/Cons
> > based on experience using it?
>
> It is definitely still in use. I use it.
That's good to hear. It does look like a nice pattern.
>
> > One concern for it is consistency. It was presented with tagged types
> > in mind, but even non tagged types provide inheritance and primitive
> > operations that can be overridden. Should it be applied to those as
> > well if used?
>
> Only if you stick to the pattern of a single type per package.
>
> I only use Jean-Pierres's naming pattern for the primary type in a
> package. Any "helper" types have more arbitrary names.
>
> Jean-Pierre's naming pattern is one of the two suggested in the Ada 95
> Quality and Style Guide.
I actually have a couple of use cases where I might have multiple "main"
types in a package. Given that possibility and also the possibility that
I might want to define non-primative operations on a given type, I was
tossing around the idea of merging the Rosen method with the one mentioned
by Luke Guest. Something like:
package Well_Named_Package is
package A_Main_Type is
type Instance is tagged private;
subtype Class is Instance'Class;
procedure Primitive_Op1(Object : Instance);
procedure Primitive_Op2(Object : Instance);
end A_Main_Type;
package Another_Main_Type is
type Instance is tagged private;
subtype Class is Instance'Class;
procedure Primitive_Op1(Object : Instance);
procedure Primitive_Op2(Object : Instance);
end Another_Main_Type;
procedure Non_Primitive_Op1(Object : A_Main_Type.Instance);
procedure Non_Primitive_Op2(Object : Another_Main_Type.Instance);
procedure Non_Primitive_Op3
(Object1 : A_Main_Type.Instance;
Object2 : Another_Main_Type.Instance);
end Well_Named_Package;
My main concern is that starts to look complex/noisy. But it gives me the
ability to have multiple main types and keep the same naming convention.
If I did that, however, I would want to keep packages with single main
types looking consistent. At worst I would have something like this:
package Well_Named_Package is
package A_Main_Type is
type Instance is tagged private;
subtype Class is Instance'Class;
procedure Primitive_Op1(Object : Instance);
procedure Primitive_Op2(Object : Instance);
end A_Main_Type;
end Well_Named_Package;
So then I would have a package in a package with no indication
of why other than it is there to have consistency with the
general case (multiple types and non primitive ops).
Though I feel like I might be going overboard.
prev parent reply other threads:[~2017-11-07 0:43 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-04 16:50 Tagged type naming convention Jere
2017-11-04 23:43 ` Luke A. Guest
2017-11-07 0:32 ` Jere
2017-11-05 19:01 ` Jacob Sparre Andersen
2017-11-07 0:43 ` Jere [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox