comp.lang.ada
 help / color / mirror / Atom feed
From: "Nick Roberts" <Nick.Roberts@dial.pipex.com>
Subject: Distinguishing type names from other identifiers
Date: 1998/01/13
Date: 1998-01-13T00:00:00+00:00	[thread overview]
Message-ID: <01bd2078$a449b460$41fd82c1@xhv46.dial.pipex.com> (raw)
In-Reply-To: dewar.884697067@merv


The technique I generally use for inventing a type identifier distinct from
identifiers I might use for objects and parameters of that type is to make
the type identifier one step more specific (and thus, usually, longer).

The justification for using a longer identifier for the type, rather than
for the objects and parameters, is that type identifiers are generally used
less often in practical source text.

For example:

   type Hour_Of_Day is range 0..23;
   type Minute_Of_Hour is range 0..59;
   type Seconds_Past_Minute is delta 0.001 range 0.000 .. 59.999;

   function To_Seconds_Past_Midnight
                   (Hour:    Hour_Of_Day;
                    Minute:  Minute_Of_Day;
                    Seconds: Seconds_Past_Minute) return Day_Duration;

This example illustrates (I hope ;-) that the use of a plural or singular
form for an identifier is not naturally to do with whether it denotes a
type, an object, a parameter, a subprogram, or whatever, but rather with
whatever concept it describes.  The choice of Seconds_Past_Minute is
perhaps a little clumsy.  I think this is the reason for many scientists'
habit of using the singular form in formal language (as well as other
archaic forms) where in common language the plural would be used; e.g. "...
if Train A be travelling at twelve metre per second ...".

On the subject of the standard Calendar package, I would probably have
chosen the identifier Day_Of_Month rather than Day_Number, and
Month_Of_Year rather than Month_Number.  However, either way, the
identifiers Day and Month can be conveniently used for identifiers of
objects and parameters of these types.

Adding _Type can be a useful way to distinguish a type, as a last resort I
would suggest.  I've always felt the 'size_t' introduced by ANSI C to be a
relatively happy compromise between size and explicitness (NPI again!).  So
I reckon adding _T is not such a sin.  But is it really worth saving the
three -- count them, THREE -- extra letters?

Come what may, I do quite strongly feel that a good programmer will strive
to achieve a maximum of clarity, and a minimum of ambiguity, when choosing
identifiers, and will not allow worries about typing sully this ideal.  It
is surely a fact that, in a few rare cases, choosing short (even terse)
notation will have advantages which outweigh other considerations.  But
these cases are RARE, so say I.

Finally, I think the declaration of the fixed-point type
Seconds_Past_Minute in the example raises another interesting question. 
Should I have used 59.999 for the upper bound, or 60.000?  Is it a bad
omission that Ada does not provide for both open and closed bounds?

-- 

Nick Roberts
Croydon, UK

Proprietor, ThoughtWing Software; Independent Software Development
Consultant
* Nick.Roberts@dial.pipex.com * Voicemail & Fax +44 181-405 1124 *
*** Eats three shredded spams every morning for breakfast ***





  reply	other threads:[~1998-01-13  0:00 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-01-07  0:00 Two simple language questions Chip Richards
1998-01-07  0:00 ` Dale Stanbrough
1998-01-07  0:00 ` Robert Dewar
1998-01-07  0:00 ` Matthew Heaney
1998-01-10  0:00   ` Two simple language questions (plural types) Michael F Brenner
1998-01-10  0:00     ` Robert Dewar
1998-01-10  0:00       ` Matthew Heaney
1998-01-10  0:00         ` Robert Dewar
1998-01-12  0:00         ` Anonymous
1998-01-12  0:00           ` Matthew Heaney
1998-01-12  0:00             ` Brian Rogoff
1998-01-13  0:00               ` Robert Dewar
1998-01-13  0:00                 ` Nick Roberts [this message]
1998-01-13  0:00                   ` Distinguishing type names from other identifiers Matthew Heaney
1998-01-14  0:00                     ` Stephen Leake
1998-01-24  0:00                       ` Matthew Heaney
1998-01-15  0:00                     ` Anonymous
1998-01-24  0:00                       ` Matthew Heaney
1998-01-24  0:00                         ` Martin M Dowie
1998-01-24  0:00                           ` Pred Nick Roberts
1998-01-25  0:00                           ` Distinguishing type names from other identifiers Matthew Heaney
1998-01-24  0:00                         ` Martin M Dowie
1998-01-15  0:00                   ` Aaro Koskinen
1998-01-17  0:00                     ` Martin M Dowie
1998-01-17  0:00                       ` Martin M Dowie
1998-01-25  0:00                       ` Matthew Heaney
1998-01-25  0:00                         ` Brian Rogoff
     [not found]                         ` <n5rs5FAStOz0Ew2+@dowie-cs.demon.co.uk>
1998-01-26  0:00                           ` Brian Rogoff
1998-01-27  0:00                             ` Martin M Dowie
1998-01-27  0:00                               ` Brian Rogoff
1998-01-27  0:00                                 ` Matthew Heaney
1998-01-28  0:00                                   ` Brian Rogoff
1998-01-28  0:00                                     ` Matthew Heaney
1998-01-29  0:00                                       ` Brian Rogoff
1998-01-30  0:00                                     ` Mats Weber
1998-01-28  0:00                                 ` Martin M Dowie
1998-01-12  0:00           ` Two simple language questions (plural types) Brian Rogoff
1998-01-11  0:00     ` Brian Rogoff
1998-01-07  0:00 ` Two simple language questions Tucker Taft
  -- strict thread matches above, loose matches on Subject: below --
1998-01-13  0:00 Distinguishing type names from other identifiers Adam Beneschan
1998-01-14  0:00 ` Brian Rogoff
1998-01-15  0:00   ` Michael F Brenner
1998-01-15  0:00     ` Nick Roberts
1998-01-16  0:00       ` Robert Dewar
1998-01-16  0:00         ` Michael F Brenner
1998-01-16  0:00           ` Robert Dewar
1998-01-16  0:00             ` Robert Dewar
1998-01-16  0:00             ` Brian Rogoff
1998-01-17  0:00               ` nabbasi
1998-01-18  0:00                 ` Robert Dewar
1998-01-21  0:00           ` Philip Brashear
1998-01-20  0:00         ` Benoit Jauvin-Girard
1998-01-20  0:00           ` Robert Dewar
1998-01-14  0:00 tmoran
1998-01-14  0:00 ` Robert Dewar
1998-01-14  0:00   ` Brian Rogoff
1998-01-14  0:00     ` nabbasi
1998-01-15  0:00       ` Brian Rogoff
1998-01-25  0:00 tmoran
1998-01-25  0:00 ` Brian Rogoff
1998-01-26  0:00   ` Nick Roberts
replies disabled

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