comp.lang.ada
 help / color / mirror / Atom feed
From: David Rasmussen <pinkfloydhomer@yahoo.com>
Subject: Re: Localized Variable Declaration
Date: Fri, 31 May 2002 17:45:49 +0200
Date: 2002-05-31T17:45:49+02:00	[thread overview]
Message-ID: <3CF79AAD.70501@yahoo.com> (raw)
In-Reply-To: SCMJ8.1075$i01.62205@news8-gui.server.ntli.net

martin.m.dowie wrote:
> "David Rasmussen" <pinkfloydhomer@yahoo.com> 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




  reply	other threads:[~2002-05-31 15:45 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 [this message]
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
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