comp.lang.ada
 help / color / mirror / Atom feed
From: geert@fozzie.sun3.iaf.nl (Geert Bosch)
Subject: Re: others clause
Date: 1996/09/02
Date: 1996-09-02T00:00:00+00:00	[thread overview]
Message-ID: <50d4fc$elf@fozzie.sun3.iaf.nl> (raw)
In-Reply-To: 3227AAA6.67C9@ghgcorp.com


Mike Bishop (mbishop@ghgcorp.com) wrote:
`` In fact, using others is a good idea even when all values are
   explicitly covered. If you add more values to the type but forget to
   modify the case statement, you can still handle the new values in
   the others choice. ''

I disagree on this. Say you have code to handle situations A, B and C and
these situations are the only ones known to you. Then it is a bad practise
to use an "others" choice, because you don't know what would be a good
reaction for others.

It is better to use no others clause. When you add some new situation D
to your program and didn't think about effects on the rest of the code, 
the compiler will show the place where you have to decide what to do about
case 'D'. Then you can think whether a "null" statement would be the
right solution, or whether you should really raise an exception if 
situation D is ever encountered at that place.

Forgetting to check if assumptions are still valid when circumstances
change is a very common and potentially disastrous error (think of the
Ariane 5). Using language features to check as much of your reasoning 
as possible is a good thing IMHO. 

Actually, one of the big dangers of object-oriented programming is
that assumptions that hold for a base class do not necessarily
hold for derived classes. Too many people think that OOP easily
scales to large projects and that code reuse is safe, without
even thinking about the possible problems.

One of the features I'm really missing in Ada is a syntax to
specify assertions, pre- and post-conditions and invariants for
code and interfaces. Compilers wouldn't have to check these
conditions, except some simple cases like static expressions,
but they (or external programs) *could* check them and moreover
compilers could use them for optimizations.

Any new revision of Ada should address this issue, since it
is so closely connected to the design goals of Ada.
-- 
E-Mail: geert@sun3.iaf.nl    
      ``I think there is a world market for maybe five computers.''
        Thomas Watson,  chairman of IBM, 1943





  parent reply	other threads:[~1996-09-02  0:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-08-29  0:00 others clause Chris Sparks
1996-08-30  0:00 ` Mike Bishop
1996-08-31  0:00   ` Robert A Duff
1996-09-02  0:00   ` Geert Bosch [this message]
1996-09-03  0:00     ` Robert Dewar
1996-09-02  0:00   ` Brian Rogoff
1996-09-03  0:00   ` Adam Beneschan
1996-08-31  0:00 ` Robert Dewar
1996-09-02  0:00 ` Stephen Bull
replies disabled

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