comp.lang.ada
 help / color / mirror / Atom feed
* Re: Distinguishing type names from other identifiers
@ 1998-01-13  0:00 Adam Beneschan
  1998-01-14  0:00 ` Brian Rogoff
  1998-01-19  0:00 ` who owns the code? was " Anonymous
  0 siblings, 2 replies; 69+ messages in thread
From: Adam Beneschan @ 1998-01-13  0:00 UTC (permalink / raw)



Nick Roberts wrote:

> 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. . . .

After following this thread, and looking at this example, I really
wonder what the objection is to using _Type suffixes.  Several people
have objected to "_Type" on the ground that it doesn't add any
informational value to the name.  But do the extra words in the above
example add any value to the name, either?  I'm not convinced that
calling the type Hour_Of_Day is any more helpful to a programmer than
just calling it Hour or Hour_Type.

Of course, I could have picked a bad example to complain about, since
there could be a use for both "Minute_Of_Hour" and "Minute_Of_Day" or
"Minute_Of_Year" or "Minutes_Elapsed" types, or something like that.
But it seems to me that in many, many cases, there just isn't any
extra value to add to the name.  So *anything* you add, whether it's a
boring suffix like _Type or a boring prefix like The_, or something
less boring that appears to contain additional information as in the
above example, is still just "noise"---in essence, a kludge to keep
the compiler happy.

So if I'm right and anything you add is just noise, I think it may be
best to use a boring suffix like _Type.  The small advantage to this
is that it may make your names easier to remember.  If you use _Type
consistently, at least you have less information to carry around in
your head, instead of trying to remember something different for each
type: "Now, let's see, did I call this one _Number, or _Of_Day, or
_Of_Hour, or what?" leading to potential errors such as the one Nick
included in his above example.

                                -- Adam

-------------------==== Posted via Deja News ====-----------------------
      http://www.dejanews.com/     Search, Read, Post to Usenet




^ permalink raw reply	[flat|nested] 69+ messages in thread
* Re: Distinguishing type names from other identifiers
@ 1998-01-25  0:00 tmoran
  1998-01-25  0:00 ` Brian Rogoff
  0 siblings, 1 reply; 69+ messages in thread
From: tmoran @ 1998-01-25  0:00 UTC (permalink / raw)



>This is the argument against _Type as a suffix.  Because it's a noise word,
>it doesn't add any new information.
  Don't think of it as the word "type", but rather as a suffix, analogous
to "s" or "ed" or "ing" in English.  Thought of that way, it's quite
arbitrary what the character string is as long as the reading community
understands what's meant.  "s" or "_t" or "_Type" are English-ish as the
multiple prefixes in "Windows Hungarian" are Bantu Kivunjo-ish.
  It's somewhat odd, actually, that most computer languages use only word
order (counting punctuation symbols as words) for parsing and don't
use spelling/prefix/suffix changes to the words themselves as grammatical
indicators.  I wonder if that will still be the case in 50 years?




^ permalink raw reply	[flat|nested] 69+ messages in thread
* Re: Distinguishing type names from other identifiers
@ 1998-01-14  0:00 tmoran
  1998-01-14  0:00 ` Robert Dewar
  0 siblings, 1 reply; 69+ messages in thread
From: tmoran @ 1998-01-14  0:00 UTC (permalink / raw)



In <884736089.2104295427@dejanews.com> Adam Beneschan said:
> best to use a boring suffix like _Type.  The small advantage to this
> is that it may make your names easier to remember.  If you use _Type
> ...
> type: "Now, let's see, did I call this one _Number, or _Of_Day, or
> _Of_Hour, or what?" leading to potential errors such as the one Nick

Not a "small" advantage at all!  Maintenance programmers should be
able to read the code fast and without being led into
misunderstanding.  A consistent pattern like "_Type" or "_T" or
plural or whatever aids this (though the example of English shows
that the human brain can deal with a limited amount of irregularity
and pure memorization, like "Integer" as a type name).  Then he
should be able to write new code quickly and correctly, without have
to look up hard-to-remember spellings and with a very low
probability that he guessed wrong.




^ permalink raw reply	[flat|nested] 69+ messages in thread
* Re: Two simple language questions (plural types)
@ 1998-01-10  0:00 Matthew Heaney
  1998-01-12  0:00 ` Anonymous
  0 siblings, 1 reply; 69+ messages in thread
From: Matthew Heaney @ 1998-01-10  0:00 UTC (permalink / raw)



In article <dewar.884450142@merv>, dewar@merv.cs.nyu.edu (Robert Dewar) wrote:


>For my tastes, I find the use of plurals to be highly (almost deliberately)
>confusing.
>
>Here the variable color is said to be something to do with colors, which
>to me strongly implies that it is a set of colors or somesuch.

Hallelujah!  Robert, once again you bring order to chaos.   I completely
agree that plural names should be used to denote, well, plural objects -
aggregates of some kind.  For example, if I have a color object that stores
the value of a single color, then of course the singular declaration

The_Color : Color; 

is preferred.  If I see

The_Color : Colors;

well then my instinct is to assume that The_Color is an aggregate of some
kind, and I would expect to see references like

   ... The_Color (1) ...

(assumes it's an array).

I generally do this sort of thing:

type Color is ...

type Color_Array is array (Positive range <>) of Color;

type Color_Stack is ...

type Color_Set is ...

I usually name array objects with a plural name, because, well, it's a
plural object:

Colors : Color_Array;

I don't buy the argument that we should compare Ada text to English text. 
The text of a computer program has its own idioms (including the one
described above), so a comparison to natural languge is not appropriate.

Do not use a plural name for a singular type.  If you're not convinced,
read the RM:

Integer is not called Integers.

Float is not called Floats.

Address is not called Addresses.

File_Type is not called File_Types.

File_Mode is not called File_Modes.

In fact, I'd like someone to point out anywhere in the RM where a plural
name is used for a singular object.  Why don't Ada programmers use the
idioms in the Ada RM?  It's VERY CONFUSING when you don't.

Please, do not use a plural name for a type whose instances denote a single
value.

--------------------------------------------------------------------
Matthew Heaney
Software Development Consultant
<mailto:matthew_heaney@acm.org>
(818) 985-1271




^ permalink raw reply	[flat|nested] 69+ messages in thread

end of thread, other threads:[~1998-01-30  0:00 UTC | newest]

Thread overview: 69+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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-18  0:00                   ` who owns the code? was " nabbasi
1998-01-18  0:00                     ` Robert Dewar
1998-01-19  0:00                       ` nabbasi
1998-01-19  0:00                         ` Robert Dewar
1998-01-20  0:00                           ` Paul Van Bellinghen
1998-01-21  0:00                             ` Robert Dewar
1998-01-21  0:00                               ` nabbasi
1998-01-22  0:00                                 ` Robert Dewar
1998-01-22  0:00                                   ` nabbasi
1998-01-21  0:00                               ` nabbasi
1998-01-22  0:00                                 ` Robert Dewar
1998-01-26  0:00                           ` Matthew Heaney
1998-01-20  0:00                       ` Anonymous
1998-01-20  0:00                         ` Robert Dewar
     [not found]               ` <69rnvv$ <dewar.885475174@me>
1998-01-23  0:00                 ` James Hopper
1998-01-22  0:00                   ` Robert Dewar
     [not found]                 ` <6a8mir$caa@nn <dewar.8855 <6a8vgd$cr7@nntp1.erinet.com>
1998-01-23  0:00                   ` Robert Dewar
1998-01-23  0:00                     ` Paul Van Bellinghen
1998-01-23  0:00                       ` Robert Dewar
1998-01-23  0:00                   ` Richard Kenner
1998-01-23  0:00                 ` James Hopper
     [not found]                 ` <6a8mir$caa@nn <dewar.8855 <6a8vgd$cr7@nn <dewar.885555487@merv>
1998-01-24  0:00                   ` James Hopper
1998-01-21  0:00           ` Philip Brashear
1998-01-20  0:00         ` Benoit Jauvin-Girard
1998-01-20  0:00           ` Robert Dewar
1998-01-19  0:00 ` who owns the code? was " Anonymous
1998-01-19  0:00   ` Robert Dewar
  -- strict thread matches above, loose matches on Subject: below --
1998-01-25  0:00 tmoran
1998-01-25  0:00 ` Brian Rogoff
1998-01-26  0:00   ` Nick Roberts
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-10  0:00 Two simple language questions (plural types) Matthew Heaney
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         ` Distinguishing type names from other identifiers Nick Roberts
1998-01-13  0:00           ` 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                 ` Martin M Dowie
1998-01-25  0:00                   ` Matthew Heaney
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

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