comp.lang.ada
 help / color / mirror / Atom feed
From: Peter C. Chapin <pchapin@sover.net>
Subject: Naming convention for classes?
Date: Tue, 03 Feb 2004 23:52:28 GMT
Date: 2004-02-03T23:52:28+00:00	[thread overview]
Message-ID: <MPG.1a89fe0b56e324d998968e@news.sover.net> (raw)


I'm a C++ person learning my way around Ada. Naturally I tend to think 
about things in a C++ way and that leads me to various questions. I 
notice, for example, that there seems to be two (at least) somewhat 
different ways to name classes in Ada. The first way gives the class 
name to a package producing the following effect.

package Date is
  type Object is private;

  procedure Advance(Item : in out Object; Step : in Integer);
  ...
end Date;

The I can create Date objects by first withing Date and then doing

  Today : Date.Object;
  ...
  Date.Advance(Today, 100);

Another approach would be to give the type itself the "nice" name and 
regard the package name as "noise" used to avoid name clashes in large 
programs. For example

package My_Library is
  type Date is private;

  procedure Advance(Item : in out Date; Step : in Integer);
  ...
end My_Library;

Then I might with My_Library and use My_Library and do

  Today : Date;
  ...
  Advance(Today, 100);

The second approach seems natural but I notice that the Charles 
component library uses the first approach and it seems to work well in 
that case. For example, in my program I do

   package Vector is new Charles.Vectors.Unbounded(
     Index_Type => Natural, Element_Type => Storage_Type);

Then I declare things to be Vector.Container_Type and use procedures 
like Vector.Append and Vector.Insert, etc. Now I'm building my own 
abstract type and I find myself waffling... should I use my intended 
name for the package or for a type inside the package? Is there some 
kind of "best practice" for this? Or am I off in the weeds here?

Thanks!

Peter



             reply	other threads:[~2004-02-03 23:52 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-02-03 23:52 Peter C. Chapin [this message]
2004-02-04  0:27 ` Naming convention for classes? Jeffrey Carter
2004-02-04  2:31   ` Peter C. Chapin
2004-02-04  8:57     ` Jean-Pierre Rosen
2004-02-04 11:52       ` Peter C. Chapin
2004-02-04 14:02         ` Jean-Pierre Rosen
2004-02-05 12:18           ` Stuart Palin
2004-02-04 14:13         ` Martin Krischik
2004-02-04  9:13     ` Preben Randhol
2004-02-04 14:57     ` Georg Bauhaus
2004-02-04 19:01     ` Jeffrey Carter
2004-02-04  8:06 ` tmoran
2004-02-04 11:49   ` Peter C. Chapin
2004-02-04 12:36     ` Preben Randhol
2004-02-04 12:41       ` Preben Randhol
2004-02-04 14:09       ` Martin Krischik
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox