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,c1131ea1fcd630a X-Google-Attributes: gid103376,public From: bobduff@world.std.com (Robert A Duff) Subject: Re: To Initialise or not Date: 1996/04/30 Message-ID: #1/1 X-Deja-AN: 152140172 references: <318508FE.204B@sanders.lockheed.com> <3184E9CE.5C7A@lmtas.lmco.com> organization: The World Public Access UNIX, Brookline, MA newsgroups: comp.lang.ada Date: 1996-04-30T00:00:00+00:00 List-Id: In article <3184E9CE.5C7A@lmtas.lmco.com>, Ken Garlington wrote: >Steve O'Neill wrote: >> >> > 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. >> >> You're not the only one. :) >I think I'm the only person in the world that _doesn't_ like this >coding style. I don't like it because I can't find a use for it. >Generally, I only want to enter information if there's some use for it, >either to make the program work, or to make it more readable, etc. I think it makes the program more readable. Well, it does if you understand my coding convention. ;-) To me, "X: Some_Pointer;" means X is a pointer, which I plan to initialize at some later point before reading it, whereas, "X: Some_Pointer := null;" means X is is a pointer, where the first use might well be "if X = null then ...". Of course, I often write "X: Some_Pointer := new T'(...);" or "X: Some_Pointer := Y;" or whatever might be appropriate. My point is just not to rely on the default value of null. Ideally, the language would require detection of uninitialized variables, and an uninitialized pointer would be different from a null pointer. The reason for not doing that are for efficiency, of course. I'm all for efficiency, but I don't like relying on this particular efficiency hack in my source code, especially since putting ":= null" shouldn't reduce efficiency. >... Otherwise, I'm just adding another >source for error (suppose, for example, there's an object called mull, nell, >etc. of a compatible type and scope, and I make a typo?) Shrug. ":= 0" might be mistaken for ":= O", for an integer, if there's an integer variable O lying around. Or ":= mull" might have meant ":= nell", for a private type, if there are "mull"s and "nell"s lying around. This doesn't seem like a big risk to me. >Some people say that initializing to null adds a hint to the reader >that it's an access. That seems (a) kind of redundant, since I should >always use the type of the object for such information, and (b) kind of >dangerous, since initial values for access types aren't always "null". >If I use the keyword to look for access values, I'll miss some. I agree -- maybe some people say it, but it's silly. To me, it's not a hint about what sort of type it is -- it's a hint that I intend to rely on the initial value of null (as opposed to using null simply to detect bogus pointer dereferences). Unfortunately, it's like any idiom -- if you're not familiar with it, it doesn't help. - Bob