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.9 required=5.0 tests=BAYES_00 autolearn=ham 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:59:34 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed1.cidera.com!Cidera!cyclone.socal.rr.com!cyclone3.kc.rr.com!news3.kc.rr.com!twister.socal.rr.com.POSTED!not-for-mail Message-ID: <3CF79DFC.50613FAF@san.rr.com> From: Darren New X-Mailer: Mozilla 4.77 [en] (Windows NT 5.0; U) X-Accept-Language: en 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 Content-Transfer-Encoding: 7bit Date: Fri, 31 May 2002 15:59:33 GMT NNTP-Posting-Host: 66.75.151.160 X-Complaints-To: abuse@rr.com X-Trace: twister.socal.rr.com 1022860773 66.75.151.160 (Fri, 31 May 2002 08:59:33 PDT) NNTP-Posting-Date: Fri, 31 May 2002 08:59:33 PDT Organization: RoadRunner - West Xref: archiver1.google.com comp.lang.ada:25092 Date: 2002-05-31T15:59:33+00:00 List-Id: David Rasmussen wrote: > I admit that in this simple example, the second looks simpler, I would suggest that this would likely be the case for all sufficiently simple examples, and that if your example is too complex for this to be true, you probably want to close the scope in which the declaration occurs before you get to the end of the function. For example, if I have a 100-line function, and I use variable Page_Length in lines 25-35 and variable Footnote_Count in lines 55 thru 70, chances are I don't want Page_Length to still be in scope while I'm calculating Footnote_Count. On the other hand, if I have a 10-line function, having all the variables in scope at once makes sense. The problem is that when you get a function large enough that all-declarations-at-the-front is too confusing, you want keywords for finding just where you've declared and initialized all these internal variables. Of course, your example might best be written as procedure .... is begin put_line("write two numbers"); declare a : integer := read(...); b : integer := read(...); c : float := a * b * 42.42; begin put_line("answer = " & c'img); end; end; or maybe something vaguely like that. :-) Note also that in C, every set of braces introduces a new scope, so something like while (yadda) { int i; i = blah(); yadda = blah2(); } means that i gets created and destructed each time thru the loop. This is not the case in Ada, so it's not obvious what the equivalent in Ada would be. loop d : some_controlled_type := blah(25); exit when d.should_exit; end; Overall, it just seems more confusing than helpful to *me* if you were to make every loop, then-part, else-part, case label, etc be a declarative scope. -- Darren New San Diego, CA, USA (PST). Cryptokeys on demand. ** http://home.san.rr.com/dnew/DNResume.html ** ** http://images.fbrtech.com/dnew/ ** My brain needs a "back" button so I can remember where I left my coffee mug.