comp.lang.ada
 help / color / mirror / Atom feed
From: dewar@cs.nyu.edu (Robert Dewar)
Subject: Re: Another aspect of comments and coding standards
Date: 1996/06/07
Date: 1996-06-07T00:00:00+00:00	[thread overview]
Message-ID: <dewar.834154978@schonberg> (raw)
In-Reply-To: dmarshalDsLuu3.Aqr@netcom.com


Dave Marshall says

"For instance, I am a little bit uncomfortable with the use of the
anonymous subtype used in the membership test."

This is a very good point, particularly applicable to the case of
enumeration types. A weakness in Ada is that enumeration types are
always ordered, and you cannot hide this ordering from a client.

Logically what is often done is to arrange a set of enumeration values
in order so that subtypes dfining appropriate subclasses
can be defined as part of the same abstraction.

However, there is no way, other than coding standards, to avoid a client
noticing that today three values happen to be contiguous and replacing

   if a = enum1 or a = enum2 or a = enum3 then

by

   if a in enum1 .. enum3 then

Now of course you have a maintenance headache, because at the abstraction
level the specific order of the enumeration literals was not defined.
A reasonable coding standard is to absolutely forbid ranges in membership
tests for enumeration types (there is no similar objection for integer
types, this comment applies only to enumeration types).





      reply	other threads:[~1996-06-07  0:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-06-06  0:00 Another aspect of comments and coding standards W. Wesley Groleau (Wes)
1996-06-07  0:00 ` Dave Marshall
1996-06-07  0:00   ` Robert Dewar [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