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.3 required=5.0 tests=BAYES_00,INVALID_MSGID 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: bobduff@world.std.com (Robert A Duff) Subject: Re: [Q] To initialise or not. Date: 1996/04/26 Message-ID: #1/1 X-Deja-AN: 151577279 references: <484274071wnr@diphi.demon.co.uk> <318109B1.3B54AFBF@escmail.orl.mmc.com> organization: The World Public Access UNIX, Brookline, MA newsgroups: comp.lang.ada Date: 1996-04-26T00:00:00+00:00 List-Id: In article <318109B1.3B54AFBF@escmail.orl.mmc.com>, Theodore E. Dennison wrote: >I suspect it is silent on this issue, because the Ada (83) LRM is >NOT silent on the issue. Section 3.2.1(18) reads: >"The execution of a program is erroneous if it attempts to evaluate a > scalar variable with an undefined value." Yes, but how do you ensure that your program is not erroneous in this way? One way, which the earlier poster is asking about, is to have a rule that all variables will be explicitly initialized on the declaration. The question is: does this coding convention help or hurt? On the one hand, it prevents the erroneous cases. On the other hand, it causes variables to be initialized to bogus values, and what *would* have been an erroneous read of an uninitialized variable, is, instead, a read of a wrong value from that variable. 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;". The problem is, of course, that if you make a mistake, the program will do who-knows-what. But I still think it makes the code more readable to avoid that bogus initial value of 0. I would very much like to see compilers check these cases at run time. I was going to suggest pragma Initialize_Scalars, but the original poster said Ada 95 features are out of the question. As an aside, I always write ":= null;" when I want to *rely* on the initial value of a pointer, even though I know that pointers are always default-initialized to null. - Bob