comp.lang.ada
 help / color / mirror / Atom feed
From: Darren New <dnew@san.rr.com>
Subject: Re: Localized Variable Declaration
Date: Fri, 31 May 2002 15:59:33 GMT
Date: 2002-05-31T15:59:33+00:00	[thread overview]
Message-ID: <3CF79DFC.50613FAF@san.rr.com> (raw)
In-Reply-To: 3CF78D3D.3030400@yahoo.com

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.



  parent reply	other threads:[~2002-05-31 15:59 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-05-31 13:24 Localized Variable Declaration David Rasmussen
2002-05-31 13:32 ` martin.m.dowie
2002-05-31 13:38   ` David Rasmussen
2002-05-31 13:50     ` martin.m.dowie
2002-05-31 14:48       ` David Rasmussen
2002-05-31 15:26         ` martin.m.dowie
2002-05-31 15:45           ` David Rasmussen
2002-05-31 18:30             ` Jeffrey Carter
2002-06-02  2:21             ` steve_H
2002-06-02  9:59               ` David Rasmussen
2002-06-02 15:06                 ` Robert Dewar
2002-06-02 15:27                   ` David Rasmussen
2002-06-02 23:25                     ` Hyman Rosen
2002-06-02 23:28                       ` David Rasmussen
2002-06-02 23:52                     ` martin.m.dowie
2002-06-02 23:58                       ` David Rasmussen
2002-06-03 11:22                         ` martin.m.dowie
2002-05-31 15:51           ` Mark Johnson
2002-05-31 17:47             ` martin.m.dowie
2002-05-31 21:53           ` tmoran
2002-06-02 15:10             ` Robert Dewar
2002-06-02 15:28               ` Vinzent Hoefler
2002-06-02 18:04               ` tmoran
2002-06-07  3:32               ` Richard Riehle
2002-05-31 15:59         ` Darren New [this message]
2002-06-02 15:20           ` Robert Dewar
2002-06-03  5:29             ` Michael Bode
2002-06-03  6:17               ` Preben Randhol
2002-06-04 10:26                 ` Simon Wright
2002-06-03 13:59               ` Marin David Condic
2002-06-05  8:36                 ` Dmitry A.Kazakov
2002-06-03 17:29               ` Pascal Obry
2002-06-16 23:34               ` Robert A Duff
2002-06-04 12:13             ` Georg Bauhaus
2002-05-31 19:00         ` Mike Silva
2002-06-01  0:58         ` Robert Dewar
2002-05-31 18:04       ` Larry Kilgallen
2002-05-31 15:06     ` Marin David Condic
2002-06-01 14:53       ` Stephen Leake
2002-06-02 21:18         ` Florian Weimer
2002-06-11  7:16         ` David Thompson
2002-05-31 18:30     ` Stephen Leake
2002-06-02  1:52 ` Stefan Skoglund
replies disabled

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