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=-0.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, FREEMAIL_REPLY autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,96ae138aab3beb03 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-05-31 08:45:50 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.icl.net!newsfeed00.sul.t-online.de!t-online.de!news-lei1.dfn.de!news-fra1.dfn.de!news.tele.dk!not-for-mail Message-ID: <3CF79AAD.70501@yahoo.com> Date: Fri, 31 May 2002 17:45:49 +0200 From: David Rasmussen User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.9) Gecko/20020412 Debian/0.9.9-6 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Localized Variable Declaration References: <3CF77998.9040806@yahoo.com> <3CF77CDA.3090805@yahoo.com> <3CF78D3D.3030400@yahoo.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Organization: TDC Internet NNTP-Posting-Host: 195.215.62.2 X-Trace: 1022859950 dtext.news.tele.dk 96090 195.215.62.2 X-Complaints-To: abuse@post.tele.dk Xref: archiver1.google.com comp.lang.ada:25089 Date: 2002-05-31T17:45:49+02:00 List-Id: martin.m.dowie wrote: > "David Rasmussen" wrote in message > news:3CF78D3D.3030400@yahoo.com... > >>int whatever(int foo) >>{ >> ... >> ... >> { // local scope starts here >> int local = 42; >> .... >> } // and ends here >> ... >>} > > > now you have 3 lines not 1! ;-) > I think you miss the point, see below. > >>So you can do the same in C++ as in Ada, and more. It's usually the >>other way around. And usually Ada has a good reason for doing things >>they way it does it. I just don't understand the justification for this >>limitation. Consider this: > > > All this is boils down to a choice of syntax and Ada is always going to > look heavy on that count - is there any area that doesn't have Ada coming > in with more keystrokes/source lines? It had never struck me as being > terribly important, if a routine is getting complex enough to warrant nested > within nested declarative blocks then I usually replace one or more with > local > subprograms (pragma Inlined if really necessary). > I am not talking about the nested scopes. I am talking about the declarations. The declaration above is one line, not 3. The nested scope adds more lines, but that was just to show you that C++ has nested scopes as well. In C++ you do this (nothing about nested scopes): int main() { cout << "Write two numbers: "; int a; cin >> a; int b; cin >> b; double c = a * b * 42.42; } The variables are declared when used, and not some centralized place in the beginning. Furthermore, they are initialized as soon as possible. Whenever one declares a variable and doesn't initialize it, an alarm should go off. This is inevitable even in small functions, in Ada, because variables have to be declared way before they are used. /David