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-06-02 08:20:47 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: dewar@gnat.com (Robert Dewar) Newsgroups: comp.lang.ada Subject: Re: Localized Variable Declaration Date: 2 Jun 2002 08:20:19 -0700 Organization: http://groups.google.com/ Message-ID: <5ee5b646.0206020720.6b91978b@posting.google.com> References: <3CF77998.9040806@yahoo.com> <3CF77CDA.3090805@yahoo.com> <3CF78D3D.3030400@yahoo.com> <3CF79DFC.50613FAF@san.rr.com> NNTP-Posting-Host: 205.232.38.14 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1023031220 13222 127.0.0.1 (2 Jun 2002 15:20:20 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 2 Jun 2002 15:20:20 GMT Xref: archiver1.google.com comp.lang.ada:25202 Date: 2002-06-02T15:20:20+00:00 List-Id: Darren New 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 ....;