From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,f92fbb4a0420dd57 X-Google-Attributes: gid103376,public From: bobduff@world.std.com (Robert A Duff) Subject: Re: some questions re. Ada/GNAT from a C++/GCC user Date: 1996/04/01 Message-ID: #1/1 X-Deja-AN: 145273176 references: <4jjul6$637@ra.nrl.navy.mil> <4jof0i$2u8@goanna.cs.rmit.edu.au> organization: The World Public Access UNIX, Brookline, MA newsgroups: comp.lang.ada Date: 1996-04-01T00:00:00+00:00 List-Id: In article <4jof0i$2u8@goanna.cs.rmit.edu.au>, Richard A. O'Keefe 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