comp.lang.ada
 help / color / mirror / Atom feed
* Localized Variable Declaration
@ 2002-05-31 13:24 David Rasmussen
  2002-05-31 13:32 ` martin.m.dowie
  2002-06-02  1:52 ` Stefan Skoglund
  0 siblings, 2 replies; 43+ messages in thread
From: David Rasmussen @ 2002-05-31 13:24 UTC (permalink / raw)


I am a C++ programmer learning Ada. So far, I love it. It is more or 
less the answer to my prayers. The only thing I miss which I think 
really enhances readability and minimizes bugs (two things that Ada 
excels at), is the ability to declare a variable "anywhere". In C++ we 
can declare a variable exactly when it is needed, which is easier to 
read, than to have to scroll up to the beginning of the function to see 
what type/size/whatever, a variable is. Also, it directly makes it 
possible more often to initialize a variable with a sensible value, 
because it is available, which it wouldn't be at the start of the 
function/scope.

Is there anyway to address this problem?

/David




^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: Localized Variable Declaration
  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-06-02  1:52 ` Stefan Skoglund
  1 sibling, 1 reply; 43+ messages in thread
From: martin.m.dowie @ 2002-05-31 13:32 UTC (permalink / raw)


"David Rasmussen" <pinkfloydhomer@yahoo.com> wrote in message
news:3CF77998.9040806@yahoo.com...
> I am a C++ programmer learning Ada. So far, I love it. It is more or
> less the answer to my prayers. The only thing I miss which I think
> really enhances readability and minimizes bugs (two things that Ada
> excels at), is the ability to declare a variable "anywhere". In C++ we
> can declare a variable exactly when it is needed, which is easier to
> read, than to have to scroll up to the beginning of the function to see
> what type/size/whatever, a variable is. Also, it directly makes it
> possible more often to initialize a variable with a sensible value,
> because it is available, which it wouldn't be at the start of the
> function/scope.
>
> Is there anyway to address this problem?

use 'declare' e.g.

procedure Blah is
begin  -- Blah
   if Some_Function then
      declare
         Local_Variable : Integer; -- only visible within the block
      begin
         -- Do something with Local_Variable
      end;
   else
   end if;
end Blah;






^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: Localized Variable Declaration
  2002-05-31 13:32 ` martin.m.dowie
@ 2002-05-31 13:38   ` David Rasmussen
  2002-05-31 13:50     ` martin.m.dowie
                       ` (2 more replies)
  0 siblings, 3 replies; 43+ messages in thread
From: David Rasmussen @ 2002-05-31 13:38 UTC (permalink / raw)


> 
> 
> use 'declare' e.g.
> 
> procedure Blah is
> begin  -- Blah
>    if Some_Function then
>       declare
>          Local_Variable : Integer; -- only visible within the block
>       begin
>          -- Do something with Local_Variable
>       end;
>    else
>    end if;
> end Blah;
> 
> 

Oh sure, but that is pretty tedious, compared to just a one line 
variable declation. The point is, to be a bit extreme, that centralized 
variable declations (e.g. at the "beginning" of the function) as done in 
C and Pascal, are evil. Variables should be declared close to where they 
are needed, IMO.

/David




^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: Localized Variable Declaration
  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 18:04       ` Larry Kilgallen
  2002-05-31 15:06     ` Marin David Condic
  2002-05-31 18:30     ` Stephen Leake
  2 siblings, 2 replies; 43+ messages in thread
From: martin.m.dowie @ 2002-05-31 13:50 UTC (permalink / raw)


"David Rasmussen" <pinkfloydhomer@yahoo.com> wrote in message
news:3CF77CDA.3090805@yahoo.com...
> Oh sure, but that is pretty tedious, compared to just a one line
> variable declation. The point is, to be a bit extreme, that centralized
> variable declations (e.g. at the "beginning" of the function) as done in
> C and Pascal, are evil. Variables should be declared close to where they
> are needed, IMO.

Sure, but that's what you get with a declare ... begin ... end. You also get
to delimit the scope in the example I gave there could have been 100 more
lines after the 'end' that just didn't need visibility of the local
variable. Can
you do that with a 'one line variable declaration'?





^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: Localized Variable Declaration
  2002-05-31 13:50     ` martin.m.dowie
@ 2002-05-31 14:48       ` David Rasmussen
  2002-05-31 15:26         ` martin.m.dowie
                           ` (3 more replies)
  2002-05-31 18:04       ` Larry Kilgallen
  1 sibling, 4 replies; 43+ messages in thread
From: David Rasmussen @ 2002-05-31 14:48 UTC (permalink / raw)


martin.m.dowie wrote:
> "David Rasmussen" <pinkfloydhomer@yahoo.com> wrote in message
> news:3CF77CDA.3090805@yahoo.com...
> 
>>Oh sure, but that is pretty tedious, compared to just a one line
>>variable declation. The point is, to be a bit extreme, that centralized
>>variable declations (e.g. at the "beginning" of the function) as done in
>>C and Pascal, are evil. Variables should be declared close to where they
>>are needed, IMO.
> 
> 
> Sure, but that's what you get with a declare ... begin ... end. You also get
> to delimit the scope in the example I gave there could have been 100 more
> lines after the 'end' that just didn't need visibility of the local
> variable. Can
> you do that with a 'one line variable declaration'?
> 
> 

You can do the same thing in C++ by just doing

int whatever(int foo)
{
     ...
     ...
     { // local scope starts here
          int local = 42;
          ....
     } // and ends here
     ...
}


very simple IMO.

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:

void something()
{
     cout << "Write two numbers: ";
     int a;
     cin >> a;
     int b;
     cin >> b;
     double c = a * b * 42.42;
}

This demonstrates very much what I mean. Variables aren't declared until 
they can immediately be given a value, even by initialization or by some 
sort of assignment immediately after declaration. This is easier to read 
and understand and minimizes bugs with uninitialized values etc. Compare 
it to:

void something()
{
     int a,b;
     double c;

     cout << "Write two numbers: ";
     cin >> a;
     cin >> b;
     c = a * b * 42.42;
}

I admit that in this simple example, the second looks simpler, but 
still, the types of variables are taken away from the local place where 
they are used, and variables aren't initialized when they are declared. 
In larger functions and larger programs in general, it makes a 
difference. Now, of course this can be done in Ada with the declare 
block, but it will be much more tedious and harder to read.

/David




^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: Localized Variable Declaration
  2002-05-31 13:38   ` David Rasmussen
  2002-05-31 13:50     ` martin.m.dowie
@ 2002-05-31 15:06     ` Marin David Condic
  2002-06-01 14:53       ` Stephen Leake
  2002-05-31 18:30     ` Stephen Leake
  2 siblings, 1 reply; 43+ messages in thread
From: Marin David Condic @ 2002-05-31 15:06 UTC (permalink / raw)


I disagree with the style issue, but the last time I checked, I could
declare variables in C in the middle of the code. They can even be scoped
with {}, IIRC. Maybe that's not "standard" C? It seems to go past the gcc
compiler I'm using.

MDC
--
Marin David Condic
Senior Software Engineer
Pace Micro Technology Americas    www.pacemicro.com
Enabling the digital revolution
e-Mail:    marin.condic@pacemicro.com


"David Rasmussen" <pinkfloydhomer@yahoo.com> wrote in message
news:3CF77CDA.3090805@yahoo.com...
>
> Oh sure, but that is pretty tedious, compared to just a one line
> variable declation. The point is, to be a bit extreme, that centralized
> variable declations (e.g. at the "beginning" of the function) as done in
> C and Pascal, are evil. Variables should be declared close to where they
> are needed, IMO.
>






^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: Localized Variable Declaration
  2002-05-31 14:48       ` David Rasmussen
@ 2002-05-31 15:26         ` martin.m.dowie
  2002-05-31 15:45           ` David Rasmussen
                             ` (2 more replies)
  2002-05-31 15:59         ` Darren New
                           ` (2 subsequent siblings)
  3 siblings, 3 replies; 43+ messages in thread
From: martin.m.dowie @ 2002-05-31 15:26 UTC (permalink / raw)


"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! ;-)

> 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).







^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: Localized Variable Declaration
  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-05-31 15:51           ` Mark Johnson
  2002-05-31 21:53           ` tmoran
  2 siblings, 2 replies; 43+ messages in thread
From: David Rasmussen @ 2002-05-31 15:45 UTC (permalink / raw)


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




^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: Localized Variable Declaration
  2002-05-31 15:26         ` martin.m.dowie
  2002-05-31 15:45           ` David Rasmussen
@ 2002-05-31 15:51           ` Mark Johnson
  2002-05-31 17:47             ` martin.m.dowie
  2002-05-31 21:53           ` tmoran
  2 siblings, 1 reply; 43+ messages in thread
From: Mark Johnson @ 2002-05-31 15:51 UTC (permalink / raw)


"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 noticed the smiley, but really...] If you really care that this
counts as three lines of code instead of one you need to get a better
line of code counter. It doesn't even have to be very exotic - one of
the simplest (and best?) ones I have seen for C merely counts lines that
have more than two non comment, non-white space characters in it. It is
about a page of code (mostly to count lines by function) and would still
count this example as one line. For Ada, you could change that from two
characters to two tokens (so you ignore null;) to get the same effect.

[and no - I don't want to get into a flame war about how to count lines
(or statements) of code :-)]
  --Mark



^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: Localized Variable Declaration
  2002-05-31 14:48       ` David Rasmussen
  2002-05-31 15:26         ` martin.m.dowie
@ 2002-05-31 15:59         ` Darren New
  2002-06-02 15:20           ` Robert Dewar
  2002-05-31 19:00         ` Mike Silva
  2002-06-01  0:58         ` Robert Dewar
  3 siblings, 1 reply; 43+ messages in thread
From: Darren New @ 2002-05-31 15:59 UTC (permalink / raw)


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.



^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: Localized Variable Declaration
  2002-05-31 15:51           ` Mark Johnson
@ 2002-05-31 17:47             ` martin.m.dowie
  0 siblings, 0 replies; 43+ messages in thread
From: martin.m.dowie @ 2002-05-31 17:47 UTC (permalink / raw)


"Mark Johnson" <mark_h_johnson@raytheon.com> wrote in message
news:3CF79BFF.B3CD0E9F@raytheon.com...
> > now you have 3 lines not 1! ;-)
> >
> [I noticed the smiley, but really...] If you really care that this
> counts as three lines of code instead of one you need to get a better
> line of code counter. It doesn't even have to be very exotic - one of
> the simplest (and best?) ones I have seen for C merely counts lines that
> have more than two non comment, non-white space characters in it. It is
> about a page of code (mostly to count lines by function) and would still
> count this example as one line. For Ada, you could change that from two
> characters to two tokens (so you ignore null;) to get the same effect.
>
> [and no - I don't want to get into a flame war about how to count lines
> (or statements) of code :-)]

:-)

Just so long as the rules are equivalent for each language... (i.e. if you
count
'begin' etc in Ada, you have to count '{' in C - the are both there for the
same
reason)





^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: Localized Variable Declaration
  2002-05-31 13:50     ` martin.m.dowie
  2002-05-31 14:48       ` David Rasmussen
@ 2002-05-31 18:04       ` Larry Kilgallen
  1 sibling, 0 replies; 43+ messages in thread
From: Larry Kilgallen @ 2002-05-31 18:04 UTC (permalink / raw)


In article <adLJ8.776$i01.53350@news8-gui.server.ntli.net>, "martin.m.dowie" <martin.m.dowie@ntlworld.com> writes:
> "David Rasmussen" <pinkfloydhomer@yahoo.com> wrote in message
> news:3CF77CDA.3090805@yahoo.com...
>> Oh sure, but that is pretty tedious, compared to just a one line
>> variable declation. The point is, to be a bit extreme, that centralized
>> variable declations (e.g. at the "beginning" of the function) as done in
>> C and Pascal, are evil. Variables should be declared close to where they
>> are needed, IMO.
> 
> Sure, but that's what you get with a declare ... begin ... end. You also get
> to delimit the scope in the example I gave there could have been 100 more
> lines after the 'end' that just didn't need visibility of the local
> variable. Can
> you do that with a 'one line variable declaration'?

procedure Blah is
begin  -- Blah
   if Some_Function then
      declare Local_Variable : Integer; begin do_something; end;
   else
   end if;
end Blah;



Oh sure, but that is pretty tedious, compared to just a one line 
variable declation. The point is, to be a bit extreme, that centralized 
variable declations (e.g. at the "beginning" of the function) as done in 
C and Pascal, are evil. Variables should be declared close to where they 
are needed, IMO.

/David




^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: Localized Variable Declaration
  2002-05-31 13:38   ` David Rasmussen
  2002-05-31 13:50     ` martin.m.dowie
  2002-05-31 15:06     ` Marin David Condic
@ 2002-05-31 18:30     ` Stephen Leake
  2 siblings, 0 replies; 43+ messages in thread
From: Stephen Leake @ 2002-05-31 18:30 UTC (permalink / raw)


David Rasmussen <pinkfloydhomer@yahoo.com> writes:

> >
> > use 'declare' e.g.
> > procedure Blah is
> > begin  -- Blah
> >    if Some_Function then
> >       declare
> >          Local_Variable : Integer; -- only visible within the block
> >       begin
> >          -- Do something with Local_Variable
> >       end;
> >    else
> >    end if;
> > end Blah;
> >
> 
> Oh sure, but that is pretty tedious, compared to just a one line
> variable declation. 

But the generated code is the same. Remember, Ada favors readability
over writeability. In this case, the 'declare' makes it _very_ clear
that you are starting a new block. That's _implied_ in C.

> The point is, to be a bit extreme, that centralized variable
> declations (e.g. at the "beginning" of the function) as done in C
> and Pascal, are evil. Variables should be declared close to where
> they are needed, IMO.

Yep. That's what declare is for.

Just because you don't like the answer, doesn't mean it isn't The
Answer :).

-- 
-- Stephe



^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: Localized Variable Declaration
  2002-05-31 15:45           ` David Rasmussen
@ 2002-05-31 18:30             ` Jeffrey Carter
  2002-06-02  2:21             ` steve_H
  1 sibling, 0 replies; 43+ messages in thread
From: Jeffrey Carter @ 2002-05-31 18:30 UTC (permalink / raw)


David Rasmussen wrote:
> 
[Mostly irrelevant stuff deleted]

To put it simply, you can't do it the C++ way in Ada because the C++ way
is not The Ada Way. In Ada declarations are always in a clearly
delimited declarative region. In C++, declarations can apparently appear
anywhere. Whether this is a Good Thing is largely a matter of taste.
Maybe you find The Ada Way so distasteful that you will create a version
of GNAT that does it the C++ way. Maybe you'll refuse to use Ada. If
not, you'll accept it and move on.

-- 
Jeff Carter
"I unclog my nose towards you."
Monty Python & the Holy Grail



^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: Localized Variable Declaration
  2002-05-31 14:48       ` David Rasmussen
  2002-05-31 15:26         ` martin.m.dowie
  2002-05-31 15:59         ` Darren New
@ 2002-05-31 19:00         ` Mike Silva
  2002-06-01  0:58         ` Robert Dewar
  3 siblings, 0 replies; 43+ messages in thread
From: Mike Silva @ 2002-05-31 19:00 UTC (permalink / raw)


David Rasmussen <pinkfloydhomer@yahoo.com> wrote in message news:<3CF78D3D.3030400@yahoo.com>...
> 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:
> 
> void something()
> {
>      cout << "Write two numbers: ";
>      int a;
>      cin >> a;
>      int b;
>      cin >> b;
>      double c = a * b * 42.42;
> }

Just as a matter of personal preference, I -hate- C++ code that has
variables shuffled in with code this way!  I find it extremely
difficult to read.  While I agree that forcing all variables to be
declared in one place is unnecessarily limiting, I personally find it
much more clear to declare -groups- of variables near where they will
be used (by corresponding -groups- of program statements), rather than
dropping them in one-by-one just before they are needed.  I think the
Ada way gives exactly the right fineness of conceptual granularity.

Mike



^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: Localized Variable Declaration
  2002-05-31 15:26         ` martin.m.dowie
  2002-05-31 15:45           ` David Rasmussen
  2002-05-31 15:51           ` Mark Johnson
@ 2002-05-31 21:53           ` tmoran
  2002-06-02 15:10             ` Robert Dewar
  2 siblings, 1 reply; 43+ messages in thread
From: tmoran @ 2002-05-31 21:53 UTC (permalink / raw)


>is there any area that doesn't have Ada coming
>in with more keystrokes/source lines?
 But faster keystrokes, I suspect.  My fingers certainly type "begin"
or "end" faster than the shifted "{" or "}".



^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: Localized Variable Declaration
  2002-05-31 14:48       ` David Rasmussen
                           ` (2 preceding siblings ...)
  2002-05-31 19:00         ` Mike Silva
@ 2002-06-01  0:58         ` Robert Dewar
  3 siblings, 0 replies; 43+ messages in thread
From: Robert Dewar @ 2002-06-01  0:58 UTC (permalink / raw)


David Rasmussen <pinkfloydhomer@yahoo.com> wrote in message news:<3CF78D3D.3030400@yahoo.com>...
> You can do the same thing in C++ by just doing
> 
> int whatever(int foo)
> {
>      ...
>      ...
>      { // local scope starts here
>           int local = 42;
>           ....
>      } // and ends here
>      ...
> }

Yes, sure, and the interesting thing is that in my experience it is far
more common to see extensive use of local declare blocks in Ada than it
is in C. I don't know why this is, because indeed narrowing the scope of
variables is an important issue for readability.

Personally I like a local declarative block being announced clearly with
declare, for me the use of { is too overloaded. For example:

   while (*a++ = *b++)
   {
      stuff
   }

and

   while (*a++ = *b++);
   {  
      stuff
   }

are uncomfortably close, and I prefer having a very definite keyword that
announces a local declare block.

As for not allowing declarations in the middle of statements, this is
very deliberate for several reasons.

Two significant reasons are:

The semantics of embedded declarations is nasty with respect to whether they
are allowed within control structures, what happens if a goto skips over them,
etc.

Forcing the use of a declare forces the writer to think about the scope of
the declarations that are introduced and end the scopes appropriately. The
C++ approach makes it easier for the programmer to ignore this, and by default
let the scope extend to the end.

Note that it is definitely not the case that C++ can do more than Ada here,
just that you have to be noisier about it in Ada. That's a choice we often
make, because we unconditionally favor the reader over the writer (for
example, consider unchecked conversion vs a cast).



^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: Localized Variable Declaration
  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
  0 siblings, 2 replies; 43+ messages in thread
From: Stephen Leake @ 2002-06-01 14:53 UTC (permalink / raw)


"Marin David Condic" <dont.bother.mcondic.auntie.spam@[acm.org> writes:

> I disagree with the style issue, but the last time I checked, I could
> declare variables in C in the middle of the code. They can even be scoped
> with {}, IIRC. Maybe that's not "standard" C? It seems to go past the gcc
> compiler I'm using.

To get the Gnu compiler to enforce the ANSI C 89
standard, use the switches -ansi -pedantic.

Anyone know when Gnu C will support C99? Or what switches that will
take?

-- 
-- Stephe



^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: Localized Variable Declaration
  2002-05-31 13:24 Localized Variable Declaration David Rasmussen
  2002-05-31 13:32 ` martin.m.dowie
@ 2002-06-02  1:52 ` Stefan Skoglund
  1 sibling, 0 replies; 43+ messages in thread
From: Stefan Skoglund @ 2002-06-02  1:52 UTC (permalink / raw)
  To: David Rasmussen

David Rasmussen wrote:
> excels at), is the ability to declare a variable "anywhere". In C++ we
> can declare a variable exactly when it is needed, which is easier to

ok everyone told you about declar .. begin .. end ;
like:
procedure foo is
i: integer;
begin
...
declare
  i:float;
begin
  -- i is now a float
  ..
end;
  -- is now an integer
end foo;

the other thing about declare is that you can control visibility
with it. Lets take ada.strings.bounded as an example
--
with ada.strings.bounded;

procedure foo is
 wanted_length: integer;
begin
   ada.integer_textio.get(wanted_length);
   -- now you need a bounded string with length 20
   
   declare
      the_string: string[wanted_length];  --  tadaam the discriminan
must be variable
                                          -- which it really isn't.
   begin
     do something with the_string
   end;
end foo;

Or was i wrong about things ???



^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: Localized Variable Declaration
  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
  1 sibling, 1 reply; 43+ messages in thread
From: steve_H @ 2002-06-02  2:21 UTC (permalink / raw)


David Rasmussen <pinkfloydhomer@yahoo.com> wrote in message news:<3CF79AAD.70501@yahoo.com>...
 
> 
> The variables are declared when used, and not some centralized place in the
> beginning. 
>

But this is why having variables declared in ONE place is better.

I always know where to go look to find where the variable was created.

In C++, I have to go scan the function code up and down to find where it was
declared.

How could this be better?



^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: Localized Variable Declaration
  2002-06-02  2:21             ` steve_H
@ 2002-06-02  9:59               ` David Rasmussen
  2002-06-02 15:06                 ` Robert Dewar
  0 siblings, 1 reply; 43+ messages in thread
From: David Rasmussen @ 2002-06-02  9:59 UTC (permalink / raw)


steve_H wrote:
> David Rasmussen <pinkfloydhomer@yahoo.com> wrote in message news:<3CF79AAD.70501@yahoo.com>...
>  
> 
>>The variables are declared when used, and not some centralized place in the
>>beginning. 
>>
> 
> 
> But this is why having variables declared in ONE place is better.
> 
> I always know where to go look to find where the variable was created.
> 
> In C++, I have to go scan the function code up and down to find where it was
> declared.
> 
> How could this be better?

I have already explained the benefits. I am not saying that this is 
always better, and I know it is largely a matter of taste. But I can 
assure you that there are real-life benefits in terms of ease of 
maintenance and readability to doing this. I think it comes down to what 
you're used to.

/David




^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: Localized Variable Declaration
  2002-06-02  9:59               ` David Rasmussen
@ 2002-06-02 15:06                 ` Robert Dewar
  2002-06-02 15:27                   ` David Rasmussen
  0 siblings, 1 reply; 43+ messages in thread
From: Robert Dewar @ 2002-06-02 15:06 UTC (permalink / raw)


David Rasmussen <pinkfloydhomer@yahoo.com> wrote in message news:<3CF9EC9F.9020203@yahoo.com>...
> I have already explained the benefits. I am not saying that this is 
> always better, and I know it is largely a matter of taste. But I can 
> assure you that there are real-life benefits in terms of ease of 
> maintenance and readability to doing this. I think it comes down to what 
> you're used to.


No, you have not explained why it is useful to have special
syntax to say that the scope is from here to the end, rather than
explicitly specifying the scope. I find that
in practice the C++ convention encourages sloppy programming in which
you get scopes unintentially
left open, for example, people write

        int t;
        t = x; x = y; y = t;

for an exchange instead of the far preferable

        {
           int t;
           t = x; x = y; y = t;
        }

why preferable? because in the first form, you do not
know if it is important that the value of y ends up in
t, so you have to remember that in case.

Yes, the first form saves the writer two keystrokes but
in Ada we don't care to save the writer effort :-)



^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: Localized Variable Declaration
  2002-05-31 21:53           ` tmoran
@ 2002-06-02 15:10             ` Robert Dewar
  2002-06-02 15:28               ` Vinzent Hoefler
                                 ` (2 more replies)
  0 siblings, 3 replies; 43+ messages in thread
From: Robert Dewar @ 2002-06-02 15:10 UTC (permalink / raw)


tmoran@acm.org wrote in message news:<RhSJ8.1445$9w7.230361117@newssvr13.news.prodigy.com>...
> >is there any area that doesn't have Ada coming
> >in with more keystrokes/source lines?
>  But faster keystrokes, I suspect.  My fingers certainly type "begin"
> or "end" faster than the shifted "{" or "}".

Hmmm! I don't think incompetent typing skills are a good
argument to introduce. Most people in fact will type
the shifted {} faster. I can quite believe that some
would type it slower (for instance if they do not have
finger memory of where the curly keys are), but in any
case speed of typing is a 100% irrelevant argument when
it comes to discussingt the design of Ada.



^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: Localized Variable Declaration
  2002-05-31 15:59         ` Darren New
@ 2002-06-02 15:20           ` Robert Dewar
  2002-06-03  5:29             ` Michael Bode
  2002-06-04 12:13             ` Georg Bauhaus
  0 siblings, 2 replies; 43+ messages in thread
From: Robert Dewar @ 2002-06-02 15:20 UTC (permalink / raw)


Darren New <dnew@san.rr.com> wrote in message news:<3CF79DFC.50613FAF@san.rr.com>...
> 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. :-)

well if we are going to give examples of good style to teach people
what Ada should look like, let's use good
style. There are two objections to the above. First it
has non-standard layout. There is no good reason for
using a layout other than the one recommended in the
RM in a case like this. Second, people overuse variables
all the time, and that's lazy (the latest versions of GNAT
warn you when you do this. Third, the assignment to C 
misleadingly implies that "mixed mode" artithmetic is allowed. Fourth,
the debugging attribute 'Img should not be used in a context like
this. Fifth, it is really good style to repeat procedure identifiers
in the end line. Sixth, it is better to copy the capitalization of
identifiers from the standard libraries. That's a lot of problems in a
few lines of code (I encourage everyone to compile code before
publishing here on the news group :-)

So let's correct that and write something that makes the
original point (which was valid and appropriately stated)
with correct code in good style:

> procedure .... is
> begin
>   Put_Line("write two numbers");
>   declare
>     a : constant Integer := Read (...);
>     b : constant Integer := Read (...);
>     c : constant Float := Float (a) * Float (b) * 42.42;
>   begin
>     Put_Line ("answer = " & Float'Image (c));
>   end;
> end ....;



^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: Localized Variable Declaration
  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:52                     ` martin.m.dowie
  0 siblings, 2 replies; 43+ messages in thread
From: David Rasmussen @ 2002-06-02 15:27 UTC (permalink / raw)


Robert Dewar wrote:
> David Rasmussen <pinkfloydhomer@yahoo.com> wrote in message news:<3CF9EC9F.9020203@yahoo.com>...
> 
>>I have already explained the benefits. I am not saying that this is 
>>always better, and I know it is largely a matter of taste. But I can 
>>assure you that there are real-life benefits in terms of ease of 
>>maintenance and readability to doing this. I think it comes down to what 
>>you're used to.
> 
> 
> 
> No, you have not explained why it is useful to have special
> syntax to say that the scope is from here to the end, rather than
> explicitly specifying the scope. I find that

Sure I haven't. And that wasn't what I said. This thread is _not_ about 
local scopes, for me. It is about declaring variables in a just-in-time 
fashion when they are needed. I didn't start talking about local scopes etc.

/David




^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: Localized Variable Declaration
  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
  2 siblings, 0 replies; 43+ messages in thread
From: Vinzent Hoefler @ 2002-06-02 15:28 UTC (permalink / raw)


dewar@gnat.com (Robert Dewar) wrote:

>Hmmm! I don't think incompetent typing skills are a good
>argument to introduce. Most people in fact will type
>the shifted {} faster.

Agree, if you say most people with a US-keyboard-layout. :-)

>I can quite believe that some
>would type it slower (for instance if they do not have
>finger memory of where the curly keys are),

On the Swiss and German layouts I use most, its more a matter of
finger acrobatics. I always have to change the position of my thumb to
the right Alt-Key and then switch to a keyboard area, I usually do not
need to reach to write English. :-)

>but in any
>case speed of typing is a 100% irrelevant argument when
>it comes to discussingt the design of Ada.

ACK. The real thing is "How fast can you read and understand it?".


Vinzent.




^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: Localized Variable Declaration
  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
  2 siblings, 0 replies; 43+ messages in thread
From: tmoran @ 2002-06-02 18:04 UTC (permalink / raw)


> Most people in fact will type the shifted {} faster.
  Please cite your data when you make a questionable claim.

> case speed of typing is a 100% irrelevant argument when
> it comes to discussingt the design of Ada.
  I quite agree.  Almost as irrelevant as comparing keystroke counts.



^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: Localized Variable Declaration
  2002-06-01 14:53       ` Stephen Leake
@ 2002-06-02 21:18         ` Florian Weimer
  2002-06-11  7:16         ` David Thompson
  1 sibling, 0 replies; 43+ messages in thread
From: Florian Weimer @ 2002-06-02 21:18 UTC (permalink / raw)


Stephen Leake <stephen.a.leake.1@gsfc.nasa.gov> writes:

> Anyone know when Gnu C will support C99?

AFAIK, support is still evolving, especially on the library side (GNU
libc).

> Or what switches that will take?

"-std=c99", or "-std=gnu99" if you want GNU extensions.




^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: Localized Variable Declaration
  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
  1 sibling, 1 reply; 43+ messages in thread
From: Hyman Rosen @ 2002-06-02 23:25 UTC (permalink / raw)


David Rasmussen wrote:
 > It is about declaring variables in a just-in-time
> fashion when they are needed.

Robert Dewar is trying to demonstrate to you that it's not just
about declaring the variables just-in-time when needed, it's
also about making them go away just-in-time when they're no
longer needed.




^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: Localized Variable Declaration
  2002-06-02 23:25                     ` Hyman Rosen
@ 2002-06-02 23:28                       ` David Rasmussen
  0 siblings, 0 replies; 43+ messages in thread
From: David Rasmussen @ 2002-06-02 23:28 UTC (permalink / raw)


Hyman Rosen wrote:
> David Rasmussen wrote:
>  > It is about declaring variables in a just-in-time
> 
>> fashion when they are needed.
> 
> 
> Robert Dewar is trying to demonstrate to you that it's not just
> about declaring the variables just-in-time when needed, it's
> also about making them go away just-in-time when they're no
> longer needed.
> 

Sure, but I can't be made responsible for every change of topic in the 
thread.

/David




^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: Localized Variable Declaration
  2002-06-02 15:27                   ` David Rasmussen
  2002-06-02 23:25                     ` Hyman Rosen
@ 2002-06-02 23:52                     ` martin.m.dowie
  2002-06-02 23:58                       ` David Rasmussen
  1 sibling, 1 reply; 43+ messages in thread
From: martin.m.dowie @ 2002-06-02 23:52 UTC (permalink / raw)


"David Rasmussen" <pinkfloydhomer@yahoo.com> wrote in message
news:3CFA3972.30904@yahoo.com...
> > No, you have not explained why it is useful to have special
> > syntax to say that the scope is from here to the end, rather than
> > explicitly specifying the scope. I find that
>
> Sure I haven't. And that wasn't what I said. This thread is _not_ about
> local scopes, for me. It is about declaring variables in a just-in-time
> fashion when they are needed. I didn't start talking about local scopes
etc.

Hmmmmmm, isn't that kind of ducking the issue? Surely there must be some
debate about the ramifications of such a style? (and for sure scope must
play
a part in such a discussion)





^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: Localized Variable Declaration
  2002-06-02 23:52                     ` martin.m.dowie
@ 2002-06-02 23:58                       ` David Rasmussen
  2002-06-03 11:22                         ` martin.m.dowie
  0 siblings, 1 reply; 43+ messages in thread
From: David Rasmussen @ 2002-06-02 23:58 UTC (permalink / raw)


martin.m.dowie wrote:
> "David Rasmussen" <pinkfloydhomer@yahoo.com> wrote in message
> news:3CFA3972.30904@yahoo.com...
> 
>>>No, you have not explained why it is useful to have special
>>>syntax to say that the scope is from here to the end, rather than
>>>explicitly specifying the scope. I find that
>>
>>Sure I haven't. And that wasn't what I said. This thread is _not_ about
>>local scopes, for me. It is about declaring variables in a just-in-time
>>fashion when they are needed. I didn't start talking about local scopes
> 
> etc.
> 
> Hmmmmmm, isn't that kind of ducking the issue? Surely there must be some
> debate about the ramifications of such a style? (and for sure scope must
> play
> a part in such a discussion)
> 

It surely is relevant. But I insist on talking about the times when it 
is a _good_ thing to do it the C++ way, as I have explained. There _are_ 
many places where it is a good way of doing things and there are very 
sound arguments as to why it is a good idea. The idea is a good one, 
regardless of scope issues.

/David




^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: Localized Variable Declaration
  2002-06-02 15:20           ` Robert Dewar
@ 2002-06-03  5:29             ` Michael Bode
  2002-06-03  6:17               ` Preben Randhol
                                 ` (3 more replies)
  2002-06-04 12:13             ` Georg Bauhaus
  1 sibling, 4 replies; 43+ messages in thread
From: Michael Bode @ 2002-06-03  5:29 UTC (permalink / raw)


dewar@gnat.com (Robert Dewar) writes:

> So let's correct that and write something that makes the
> original point (which was valid and appropriately stated)
> with correct code in good style:
> 
> > procedure .... is
> > begin
> >   Put_Line("write two numbers");
> >   declare
> >     a : constant Integer := Read (...);
> >     b : constant Integer := Read (...);
> >     c : constant Float := Float (a) * Float (b) * 42.42;
> >   begin
> >     Put_Line ("answer = " & Float'Image (c));
> >   end;
> > end ....;

Could someone please help a poor Ada beginner and tell me when to
leave a blank between a function name and its parameter list and when
not? I personally find the above Put_Line("write two number"); more
readable than Float := Float (a) * Float (b) * 42.42; because I think
of a function and its parameters as a unity, but I've seen the blanks
in textbooks quite often. OTHO "Ada Quality and Style" favors the
Put_Line(...)

PS: No Holy War intended.



^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: Localized Variable Declaration
  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
                                 ` (2 subsequent siblings)
  3 siblings, 1 reply; 43+ messages in thread
From: Preben Randhol @ 2002-06-03  6:17 UTC (permalink / raw)


On 03 Jun 2002 07:29:33 +0200, Michael Bode wrote:
> 
> Could someone please help a poor Ada beginner and tell me when to
> leave a blank between a function name and its parameter list and when
> not? I personally find the above Put_Line("write two number"); more
> readable than Float := Float (a) * Float (b) * 42.42; because I think
> of a function and its parameters as a unity, but I've seen the blanks
> in textbooks quite often. OTHO "Ada Quality and Style" favors the
> Put_Line(...)

If you compile with GNAT use the -gnats option.

Preben



^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: Localized Variable Declaration
  2002-06-02 23:58                       ` David Rasmussen
@ 2002-06-03 11:22                         ` martin.m.dowie
  0 siblings, 0 replies; 43+ messages in thread
From: martin.m.dowie @ 2002-06-03 11:22 UTC (permalink / raw)


"David Rasmussen" <pinkfloydhomer@yahoo.com> wrote in message
news:3CFAB12A.6050204@yahoo.com...
> It surely is relevant. But I insist on talking about the times when it
> is a _good_ thing to do it the C++ way, as I have explained. There _are_
> many places where it is a good way of doing things and there are very
> sound arguments as to why it is a good idea. The idea is a good one,
> regardless of scope issues.

fair enough :-)






^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: Localized Variable Declaration
  2002-06-03  5:29             ` Michael Bode
  2002-06-03  6:17               ` Preben Randhol
@ 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
  3 siblings, 1 reply; 43+ messages in thread
From: Marin David Condic @ 2002-06-03 13:59 UTC (permalink / raw)


C and C++ programmers tend to write things without spaces or underscores, so
you can tell their origin when you see Ada code that looks like:

SomeProcedureName(X,Y,Z);

Ada programmers make more frequent use of spaces and underscores, so it is
much more common to see:

Some_Procedure_Name (X, Y, Z);

To a large extent, it is a matter of taste, but you can use the ARM and Ada
Quality & Style as good guidelines. In general, I suggest this: When working
on a program someone else wrote, stick to whatever style they used. When
working on a group project, get everyone to agree to some style and stick to
it - but avoid nit-picking arguments over every single comma or space. When
working strictly on your own, use any style you like - but be consistent.

There are various tools that can be used to format Ada code and their use
will bring you a certain consistency, but I've never found them to be a 100%
substitute for hand-formatting and I've not encountered one that ever
formatted things the way *I* would do it. :-) (Well, except for one I wrote
a bunch of years ago for Ada83 - and even then, my style has evolved since
then & it doesn't work for Ada95. :-)

MDC
--
Marin David Condic
Senior Software Engineer
Pace Micro Technology Americas    www.pacemicro.com
Enabling the digital revolution
e-Mail:    marin.condic@pacemicro.com


"Michael Bode" <m.g.bode@web.de> wrote in message
news:m37klhkk02.fsf@jupiter.solar.system...
>
> Could someone please help a poor Ada beginner and tell me when to
> leave a blank between a function name and its parameter list and when
> not? I personally find the above Put_Line("write two number"); more
> readable than Float := Float (a) * Float (b) * 42.42; because I think
> of a function and its parameters as a unity, but I've seen the blanks
> in textbooks quite often. OTHO "Ada Quality and Style" favors the
> Put_Line(...)
>
> PS: No Holy War intended.





^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: Localized Variable Declaration
  2002-06-03  5:29             ` Michael Bode
  2002-06-03  6:17               ` Preben Randhol
  2002-06-03 13:59               ` Marin David Condic
@ 2002-06-03 17:29               ` Pascal Obry
  2002-06-16 23:34               ` Robert A Duff
  3 siblings, 0 replies; 43+ messages in thread
From: Pascal Obry @ 2002-06-03 17:29 UTC (permalink / raw)



Michael Bode <m.g.bode@web.de> writes:

> Could someone please help a poor Ada beginner and tell me when to
> leave a blank between a function name and its parameter list and when
> not? I personally find the above Put_Line("write two number"); more
> readable than Float := Float (a) * Float (b) * 42.42; because I think
> of a function and its parameters as a unity, but I've seen the blanks
> in textbooks quite often. OTHO "Ada Quality and Style" favors the
> Put_Line(...)

All styles (well most of them :) are ok as long it is consistent. I do prefer
having a space in those cases. And since I can't myself ensure that I use a
consistent style I prefer to let the compiler do this low-level job. For this
I always use -gnaty to compile my sources.

> PS: No Holy War intended.

Just my 2 cents,
Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|         http://perso.wanadoo.fr/pascal.obry
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595



^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: Localized Variable Declaration
  2002-06-03  6:17               ` Preben Randhol
@ 2002-06-04 10:26                 ` Simon Wright
  0 siblings, 0 replies; 43+ messages in thread
From: Simon Wright @ 2002-06-04 10:26 UTC (permalink / raw)


Preben Randhol <randhol+abuse@pvv.org> writes:

> On 03 Jun 2002 07:29:33 +0200, Michael Bode wrote:
> > 
> > Could someone please help a poor Ada beginner and tell me when to
> > leave a blank between a function name and its parameter list and when
> > not? I personally find the above Put_Line("write two number"); more
> > readable than Float := Float (a) * Float (b) * 42.42; because I think
> > of a function and its parameters as a unity, but I've seen the blanks
> > in textbooks quite often. OTHO "Ada Quality and Style" favors the
> > Put_Line(...)
> 
> If you compile with GNAT use the -gnats option.

-gnaty



^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: Localized Variable Declaration
  2002-06-02 15:20           ` Robert Dewar
  2002-06-03  5:29             ` Michael Bode
@ 2002-06-04 12:13             ` Georg Bauhaus
  1 sibling, 0 replies; 43+ messages in thread
From: Georg Bauhaus @ 2002-06-04 12:13 UTC (permalink / raw)


Robert Dewar <dewar@gnat.com> wrote:
:  Sixth, it is better to copy the capitalization of
: identifiers from the standard libraries. 
at this stage...
It seems like we are witnessing a repeated evolutionary
process of slowly arriving at well written small letter words
in appropriate font variants. Enjoy Emacs 21.

.-) :-) :-)




^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: Localized Variable Declaration
  2002-06-03 13:59               ` Marin David Condic
@ 2002-06-05  8:36                 ` Dmitry A.Kazakov
  0 siblings, 0 replies; 43+ messages in thread
From: Dmitry A.Kazakov @ 2002-06-05  8:36 UTC (permalink / raw)


Marin David Condic wrote:

> C and C++ programmers tend to write things without spaces or underscores,
> so you can tell their origin when you see Ada code that looks like:
> 
> SomeProcedureName(X,Y,Z);
> 
> Ada programmers make more frequent use of spaces and underscores, so it is
> much more common to see:
> 
> Some_Procedure_Name (X, Y, Z);
> 
> To a large extent, it is a matter of taste,

Interestingly is that it is true in a literal sense. I have no logical 
explanation for this, but I tend to write SomeProcedureName in C++ and 
Some_Procedure_Name in Ada. I tried to stick to one way for both, but 
noticed that purely aesthetically first looks better in C++ while second is 
better for Ada.

-- 
Regards,
Dmitry Kazakov
www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: Localized Variable Declaration
  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
  2 siblings, 0 replies; 43+ messages in thread
From: Richard Riehle @ 2002-06-07  3:32 UTC (permalink / raw)


Robert Dewar wrote:

> Hmmm! I don't think incompetent typing skills are a good
> argument to introduce. Most people in fact will type
> the shifted {} faster. I can quite believe that some
> would type it slower (for instance if they do not have
> finger memory of where the curly keys are), but in any
> case speed of typing is a 100% irrelevant argument when
> it comes to discussingt the design of Ada.

Also, when using an industrial-strength editor, one can
configure the keyboard to reverse the  [ with the { and
the ] with the }.   This is certainly faster than typing
begin and end.    That being said, I dislike the fact that
the {  } in the C family of languages does not let me
name them so I can easily detect their relationship to
each other.   For example,  I would like to be able to
do what I can do in Ada with begin ... end.   Consider,

                   Block_Name:
                   {
                        some C code here
                   } Block_Name;

and have it detected and verified by the compiler.

Richard Riehle






^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: Localized Variable Declaration
  2002-06-01 14:53       ` Stephen Leake
  2002-06-02 21:18         ` Florian Weimer
@ 2002-06-11  7:16         ` David Thompson
  1 sibling, 0 replies; 43+ messages in thread
From: David Thompson @ 2002-06-11  7:16 UTC (permalink / raw)


Stephen Leake <stephen.a.leake.1@gsfc.nasa.gov> wrote :
> "Marin David Condic" <dont.bother.mcondic.auntie.spam@[acm.org> writes:
>
> > I disagree with the style issue, but the last time I checked, I could
> > declare variables in C in the middle of the code. They can even be scoped
> > with {}, IIRC. Maybe that's not "standard" C? It seems to go past the gcc
> > compiler I'm using.
>
C has always (or at least since before K&R1) allowed declarations
at the beginning of any compound statement (delimited by braces),
not just the compound statement which is the body of a function.
This distinction was not kept clear in most of the thread.

> To get the Gnu compiler to enforce the ANSI C 89
> standard, use the switches -ansi -pedantic.
>
> Anyone know when Gnu C will support C99? ...

Yep.  Note that C99, like C++ and GNU-C, allows declarations
"anywhere" a statement is valid (except immediately after a label).
(Like PL/1.  <G>)  And C99 like C++ has a form of the for statement
that locally declares the loop variable.

Hmm, anyone recall which way(s) algol went on this?
IIRC LISP allows declarations anywhere as well as nowhere.
(That is, they are optional, but if used can be anywhere.)

--
- David.Thompson 1 now at worldnet.att.net








^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: Localized Variable Declaration
  2002-06-03  5:29             ` Michael Bode
                                 ` (2 preceding siblings ...)
  2002-06-03 17:29               ` Pascal Obry
@ 2002-06-16 23:34               ` Robert A Duff
  3 siblings, 0 replies; 43+ messages in thread
From: Robert A Duff @ 2002-06-16 23:34 UTC (permalink / raw)


Michael Bode <m.g.bode@web.de> writes:

> dewar@gnat.com (Robert Dewar) writes:
> 
> > So let's correct that and write something that makes the
> > original point (which was valid and appropriately stated)
> > with correct code in good style:
> > 
> > > procedure .... is
> > > begin
> > >   Put_Line("write two numbers");
> > >   declare
> > >     a : constant Integer := Read (...);
> > >     b : constant Integer := Read (...);
> > >     c : constant Float := Float (a) * Float (b) * 42.42;
> > >   begin
> > >     Put_Line ("answer = " & Float'Image (c));
> > >   end;
> > > end ....;
> 
> Could someone please help a poor Ada beginner and tell me when to
> leave a blank between a function name and its parameter list and when
> not? I personally find the above Put_Line("write two number"); more
> readable than Float := Float (a) * Float (b) * 42.42; because I think
> of a function and its parameters as a unity, but I've seen the blanks
> in textbooks quite often. OTHO "Ada Quality and Style" favors the
> Put_Line(...)

There is no universal agreement on this.  I suspect Robert meant to
put a blank after Put_Line, above, because that's the GNAT style.

The Ada RM style is not to put a blank before the "(".  The GNAT style
is to put in that blank.  I find the GNAT style ugly, particularly when
there's a selected component:

    ... Get_Something(X, Y).Some_Component ...

in the GNAT style would be:

    ... Get_Something (X, Y).Some_Component ...

which makes it look like ".Some_Component" is being applied to "(X, Y)",
whereas it is actually being applied to "Get_Something(X, Y)".

Not a big deal.  ;-)

> PS: No Holy War intended.

;-)  These kinds of trivialities are what holy wars are made of!

- Bob



^ permalink raw reply	[flat|nested] 43+ messages in thread

end of thread, other threads:[~2002-06-16 23:34 UTC | newest]

Thread overview: 43+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

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