comp.lang.ada
 help / color / mirror / Atom feed
From: bobduff@world.std.com (Robert A Duff)
Subject: Re: To Initialise or not
Date: 1996/04/30
Date: 1996-04-30T00:00:00+00:00	[thread overview]
Message-ID: <DqnGoz.10v@world.std.com> (raw)
In-Reply-To: 3184E9CE.5C7A@lmtas.lmco.com


In article <3184E9CE.5C7A@lmtas.lmco.com>,
Ken Garlington  <garlingtonke@lmtas.lmco.com> 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




  parent reply	other threads:[~1996-04-30  0:00 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-04-29  0:00 To Initialise or not Steve O'Neill
1996-04-29  0:00 ` Ken Garlington
1996-04-29  0:00   ` Robert Dewar
1996-04-30  0:00     ` Ken Garlington
1996-04-30  0:00   ` Robert A Duff [this message]
1996-04-30  0:00     ` Robert A Duff
1996-04-30  0:00     ` Ken Garlington
1996-04-30  0:00       ` Robert A Duff
1996-05-01  0:00         ` Keith Thompson
1996-05-01  0:00           ` Theodore E. Dennison
1996-05-01  0:00             ` Dale Stanbrough
1996-05-01  0:00             ` Robert A Duff
1996-05-02  0:00               ` Michael F Brenner
1996-05-02  0:00                 ` Robert A Duff
1996-05-04  0:00                   ` Kevin D. Heatwole
1996-05-02  0:00               ` Theodore E. Dennison
1996-05-02  0:00                 ` Robert A Duff
1996-05-02  0:00                 ` Chris Warack <sys mgr>
1996-05-02  0:00                   ` Robert A Duff
1996-05-06  0:00                   ` Ken Garlington
1996-05-06  0:00               ` Ken Garlington
1996-05-07  0:00                 ` Robert A Duff
1996-05-08  0:00                   ` Ken Garlington
1996-05-08  0:00                     ` Robert A Duff
1996-05-09  0:00                       ` Ken Garlington
1996-05-09  0:00                         ` Robert A Duff
1996-05-02  0:00             ` Robert Dewar
1996-05-02  0:00               ` Robert A Duff
1996-05-02  0:00               ` Theodore E. Dennison
1996-05-01  0:00           ` Robert A Duff
1996-05-02  0:00             ` Keith Thompson
1996-05-03  0:00               ` Robert A Duff
1996-05-06  0:00           ` Ken Garlington
1996-05-06  0:00         ` Ken Garlington
1996-05-07  0:00           ` Robert A Duff
1996-05-08  0:00             ` Ken Garlington
1996-05-09  0:00               ` Robert A Duff
1996-05-10  0:00                 ` Robert A Duff
1996-05-10  0:00                   ` Ken Garlington
1996-05-10  0:00                     ` Robert A Duff
1996-05-10  0:00                       ` Ken Garlington
1996-05-11  0:00                         ` David Kristola
1996-05-11  0:00                           ` Robert A Duff
1996-05-11  0:00                         ` Robert A Duff
1996-05-13  0:00                 ` Ken Garlington
1996-05-13  0:00                   ` Robert A Duff
1996-05-13  0:00                     ` Ken Garlington
1996-05-13  0:00                   ` Ken Garlington
1996-05-13  0:00                     ` Robert A Duff
1996-05-13  0:00                       ` Ken Garlington
1996-05-01  0:00     ` Patrick Richard Wibbeler
1996-05-06  0:00       ` Ken Garlington
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox