comp.lang.ada
 help / color / mirror / Atom feed
From: dewar@gnat.com (Robert Dewar)
Subject: Re: Localized Variable Declaration
Date: 2 Jun 2002 08:20:19 -0700
Date: 2002-06-02T15:20:20+00:00	[thread overview]
Message-ID: <5ee5b646.0206020720.6b91978b@posting.google.com> (raw)
In-Reply-To: 3CF79DFC.50613FAF@san.rr.com

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



  reply	other threads:[~2002-06-02 15:20 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
2002-06-02 15:20           ` Robert Dewar [this message]
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