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=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,8c87bf30faa2b6b X-Google-Attributes: gid103376,public From: "Thorsten Behrens" Subject: Re: [Q] To initialise or not. Date: 1996/04/27 Message-ID: <75602294@dorunth.hb.north.de>#1/1 X-Deja-AN: 151772604 references: <484274071wnr@diphi.demon.co.uk> <318109B1.3B54AFBF@escmail.orl.mmc.com> content-type: text/plain; charset=iso-8859-1 organization: Private site of 'Kommunikationsnetz NorthNet Bremen e.V.' mime-version: 1.0 reply-to: "thorsten.behrens" newsgroups: comp.lang.ada Date: 1996-04-27T00:00:00+00:00 List-Id: Captain, bei Sternzeit Fri, 26 Apr 1996 18:55:28 GMT empfingen wir folgende Nachricht von Robert A Duff: >... > My personal coding convention is to *not* initialize variables if I know > they will be properly initialized later. E.g.: > > declare > X: Integer; > begin > if ... then > X := 12; > else > X := 13; > end if; > ... -- some reads of X > > In the above, I would *not* write "X: Integer := 0;". This initialization would indeed make no sense. But in the example above (and in many similar cases) you could have used: declare X : INTEGER := 12; -- 'X' is initialized to 12 here because ... -- It will be changed to '13' under the following circumstances ... -- in the code piece following. begin if not ... then X := 13; end if; ... -- some reads of 'X' Of course, you would have to write some additional comment. But may be this adds some details to your source some other people reading it may need to get a deeper understanding (of course not in this simple example). I tend to give all my declarations some initial value (if possible) _and_ an initial comment (giving a shorter or longer text about its usage and the background of this variable). In my eyes this saves me from having non-initialized variables (causing errors which are sometimes nasty to find) and it saves people reviewing my sources from wasting too much time to guess what I was thinking when "inventing" a variable (normally, I would not use a variable called 'X', but instead would have called it 'Some_Meaningful_Name'). BTW, a former colleague of mine called me a 'secretary' when he found too many comments in my source code. That the other side of the medal. >... > I would very much like to see compilers check these cases at run time. You could use some kind of software review tools for this. ----------------------------------------------------------------------------- - Thorsten Behrens /// Voice : +49 421 351252 - - Buddestr. 39 \\\/// e-mail: thorsten.behrens@dorunth.hb.north.de - - 28215 Bremen \XX/ - ----------------------------------------------------------------------------- - aka Aggli 'if it moves, kill it' the Fist - -----------------------------------------------------------------------------