comp.lang.ada
 help / color / mirror / Atom feed
From: bobduff@world.std.com (Robert A Duff)
Subject: Re: some questions re. Ada/GNAT from a C++/GCC user
Date: 1996/04/01
Date: 1996-04-01T00:00:00+00:00	[thread overview]
Message-ID: <Dp76GL.21M@world.std.com> (raw)
In-Reply-To: 4jof0i$2u8@goanna.cs.rmit.edu.au

In article <4jof0i$2u8@goanna.cs.rmit.edu.au>,
Richard A. O'Keefe <ok@goanna.cs.rmit.edu.au> wrote:
>I am on record as being a fan of Algol 68, which is where C++ got the idea
>of mixing declarations and statements.  However, it is quite false to say
>that Ada requires 'declare', 'begin' and 'end' "for no good reason".
>
>In C++, declarations and statements _can_ look very similar.

The solution, IMHO, is to make the syntax of declarations different from
the syntax of statements.  Then, you can tell the difference, without
the extra cue of "above lie declarations, below lie statements".  In
fact, in Ada, declarations look different enough for my taste.  I can
tell them apart pretty easily, without any begin/end cues.  Besides,
what's the big deal?  If you mistake one for the other, what bugs does
that cause?

>...  See section
>6.8 of Eliis & Stroustrup, which says "to disambiguate, the whole
>statement may have to be examined to determine if it is an 
>expression-statement of a declaration".

A syntactic problem that C++ inherits from C.

>This creates a problem for people trying to read long listings:  when they
>want to find the declaration of a local identifier, it can be hard to see
>which lines are declarations, let alone which is the right declaration.
>
>C++ programmers deal with this a simple way:  they avoid long functions.
>
>Ada programmers do this too, but Ada helps with two things:

Small functions are a good idea.  But that doesn't imply that the
"right" place to split a piece of code out into a separate function is
exactly where I happen to want a very-local variable.  I don't want to
clutter the namespace with function names that have no conceptual use,
but are merely there because the language forced a function call at that
point.  After all, we don't require that every loop body contain exactly
one function call.

>(1) For variables and constants, the identifier being declared is the first
>    thing in the line.  (Ada allows, but does not require, several identifiers
>    in one declaration.  I try to avoid this.)
>
>(2) The declarations are located in specially marked regions of code.
>    Repeat
>	look up to outer 'procedure', 'function', 'declare', 'package'
>	scan down to 'begin' looking for identifier
>    until found.

Yeah, or you could use "grep".  The above algorithm doesn't work too
well if the declaration you're looking for is in another library
package.

>Of _course_ this is heavy-weight for tiny examples, but tiny examples don't
>benefit much from intermingled declarations either.

I suppose.  But you could use the same argument against while loops and
if statements.  After all, if you keep your procedures small enough,
then an algorithm written entirely with goto statements isn't so hard to
understand.

- Bob




  reply	other threads:[~1996-04-01  0:00 UTC|newest]

Thread overview: 80+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-03-27  0:00 some questions re. Ada/GNAT from a C++/GCC user Bill Newman
1996-03-27  0:00 ` Robert Dewar
1996-03-28  0:00   ` Brian Rogoff
1996-03-29  0:00     ` John G. Volan
1996-03-30  0:00       ` Mike Young
1996-03-30  0:00         ` Ted Dennison
1996-03-31  0:00           ` Mike Young
1996-03-30  0:00       ` Robert A Duff
1996-03-31  0:00         ` John G. Volan
1996-03-31  0:00           ` Mike Young
1996-04-02  0:00             ` Glenn H. Porter
1996-04-02  0:00               ` Jonas Nygren
1996-04-02  0:00               ` Robert Dewar
1996-04-03  0:00               ` Geert Bosch
1996-04-03  0:00                 ` Robert Dewar
1996-04-01  0:00           ` Robert A Duff
1996-04-03  0:00             ` Scott Leschke
1996-04-04  0:00               ` AdaWorks
1996-04-01  0:00           ` Bruce.Conroy
1996-03-31  0:00         ` Robert Dewar
1996-04-01  0:00           ` Norman H. Cohen
1996-04-01  0:00       ` Norman H. Cohen
1996-04-01  0:00         ` Mike Young
1996-04-02  0:00           ` Robert Dewar
1996-04-02  0:00           ` Norman H. Cohen
1996-04-02  0:00           ` David Shochat
1996-04-02  0:00             ` Mike Young
1996-04-01  0:00         ` Robert A Duff
1996-04-01  0:00           ` Mike Young
1996-04-02  0:00             ` Norman H. Cohen
1996-04-02  0:00             ` Robert A Duff
1996-03-28  0:00   ` Norman H. Cohen
1996-03-28  0:00 ` Scott Leschke
1996-03-29  0:00   ` Robert A Duff
1996-03-30  0:00     ` Richard Pitre
1996-03-30  0:00       ` Robert A Duff
1996-03-31  0:00         ` AdaWorks
1996-04-01  0:00           ` Robert A Duff
1996-04-01  0:00             ` Norman H. Cohen
1996-04-01  0:00             ` Ken Garlington
1996-04-01  0:00               ` Robert A Duff
1996-04-02  0:00                 ` Ken Garlington
1996-04-02  0:00                   ` Robert A Duff
1996-04-02  0:00                     ` Ken Garlington
1996-04-02  0:00                       ` Robert A Duff
1996-04-03  0:00                         ` David Emery
1996-04-03  0:00                         ` Ken Garlington
1996-04-09  0:00                           ` Matt Kennel
1996-04-02  0:00                 ` Tucker Taft
1996-04-02  0:00                   ` Felaco
1996-04-02  0:00                     ` Robert Dewar
1996-04-03  0:00                     ` Mark A Biggar
1996-04-01  0:00             ` AdaWorks
1996-04-01  0:00               ` Mike Young
1996-04-02  0:00                 ` Robert Dewar
1996-04-02  0:00                 ` AdaWorks
1996-04-01  0:00         ` Richard A. O'Keefe
1996-04-01  0:00           ` Robert A Duff [this message]
1996-04-01  0:00         ` Robert Dewar
1996-04-02  0:00       ` Robert I. Eachus
1996-03-29  0:00   ` Robert I. Eachus
1996-03-29  0:00   ` Bill Newman
1996-03-28  0:00 ` Ted Dennison
1996-03-29  0:00   ` Adam Beneschan
1996-03-29  0:00 ` Robert A Duff
1996-03-29  0:00   ` Brian Rogoff
1996-04-01  0:00     ` Mark A Biggar
1996-04-01  0:00       ` Robert A Duff
1996-03-30  0:00   ` Iterators (was Re: some questions re. Ada/GNAT from a C++/GCC user) Robert I. Eachus
1996-03-31  0:00     ` Mike Young
1996-03-31  0:00       ` Fergus Henderson
     [not found]   ` <4jlj79$h1k@Nntp1.mcs.net>
1996-04-01  0:00     ` some questions re. Ada/GNAT from a C++/GCC user Robert A Duff
1996-04-02  0:00       ` Kevin Cline
1996-04-02  0:00         ` Robert A Duff
1996-04-01  0:00   ` Iterators (was Re: some questions re. Ada/GNAT from a C++/GCC user) Robert I. Eachus
1996-04-04  0:00   ` some questions re. Ada/GNAT from a C++/GCC user Jon S Anthony
1996-03-30  0:00 ` Simon Wright
1996-04-01  0:00 ` Laurent Guerby
1996-04-01  0:00   ` Robert A Duff
  -- strict thread matches above, loose matches on Subject: below --
1996-03-28  0:00 Simon Johnston
replies disabled

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