Jump to page: 1 2 3
Thread overview
Bjarne Stroustrup takes issue with the 'null' keyword
May 26, 2005
Sam
May 26, 2005
Brad Beveridge
May 26, 2005
Sean Kelly
May 27, 2005
Walter
May 27, 2005
imr1984
May 28, 2005
Matthew
May 26, 2005
Hasan Aljudy
May 27, 2005
Sam
May 27, 2005
Tom S
May 27, 2005
Hasan Aljudy
May 27, 2005
Matthias Becker
May 27, 2005
Ben Hinkle
May 27, 2005
Ben Hinkle
May 27, 2005
Matthias Becker
May 27, 2005
Ben Hinkle
May 27, 2005
clayasaurus
May 27, 2005
Kris
May 27, 2005
Derek Parnell
May 27, 2005
Chris Sauls
May 27, 2005
Derek Parnell
May 27, 2005
Chris Sauls
May 27, 2005
Hasan Aljudy
May 27, 2005
t
May 27, 2005
Hasan Aljudy
May 27, 2005
Dejan Lekic
May 26, 2005
Should I use NULL or 0?

To quote Bjarne Stroustrup, the god of C++:

"In C++, the definition of NULL is 0, so there is only an aesthetic difference. I prefer to avoid macros, so I use 0. Another problem with NULL is that people sometimes mistakenly believe that it is different from 0 and/or not an integer. In pre-standard code, NULL was/is sometimes defined to something unsuitable and therefore had/has to be avoided. That's less common these days."

---->  http://www.research.att.com/~bs/bs_faq2.html#null

So as you can see, even the great Bjarne Stroustrup believes we don't need a 'null' keyword.

He also believes that garbage collection was never needed in C++, as
std::auto_ptr<T> can handle everything.
I don't fully agree with this...  But I can't really say he's wrong here either.

I guess my question is: What has D taken from this "so called" wisdom from a "so called" guru?


May 26, 2005
Sam wrote:
> Should I use NULL or 0?
> 
> To quote Bjarne Stroustrup, the god of C++:

D isn't C++ though.

> I guess my question is: What has D taken from this "so called" wisdom from a "so
> called" guru?
Well, I get the impression that many people interested in D think that C++ is a complete dog of a language and are looking for something better.  That something better is D.  In D, null is actually a keyword - not just zero.  Due to stronger typing in D, there is an actual distinguishment between null and 0.

Brad
May 26, 2005
In article <d75g34$6eb$1@digitaldaemon.com>, Sam says...
>
>
>Should I use NULL or 0?
>
>To quote Bjarne Stroustrup, the god of C++:
>
>"In C++, the definition of NULL is 0, so there is only an aesthetic difference. I prefer to avoid macros, so I use 0. Another problem with NULL is that people sometimes mistakenly believe that it is different from 0 and/or not an integer. In pre-standard code, NULL was/is sometimes defined to something unsuitable and therefore had/has to be avoided. That's less common these days."
>
>---->  http://www.research.att.com/~bs/bs_faq2.html#null
>
>So as you can see, even the great Bjarne Stroustrup believes we don't need a 'null' keyword.
>
>He also believes that garbage collection was never needed in C++, as
>std::auto_ptr<T> can handle everything.
>I don't fully agree with this...  But I can't really say he's wrong here either.
>
>I guess my question is: What has D taken from this "so called" wisdom from a "so called" guru?

FWIW, here is a bit from the C++ standard that discusses NULL:

4.10 - A null pointer constant is an integral constant expression (5.19) rvalue of integer type that evaluates to zero. A null pointer constant can be converted to a pointer type; the result is the null pointer value of that type and is distinguishable from every other value of pointer to object or pointer to function type. Two null pointer values of the same type shall compare equal. The conversion of a null pointer constant to a pointer to cv-qualified type is a single conversion, and not the sequence of a pointer conversion followed by a qualification conversion (4.4).

It's worth noting that this makes zero behave differently than *any other integer value* as only zero is implicitly convertible to a pointer type.  It also violates C++ type safety.  Besides, which is more meaningful, NULL or 0? If that isn't enough, Bjarne Stroustrup and Herb Sutter proposed a language extension for the next iteration of the C++ standard: the addition of a 'nullptr' constant (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1488.pdf).  In short, I think there's ample support for the existence of 'null' in D :)


Sean


May 26, 2005
Sam wrote:
> Should I use NULL or 0?
> 
> To quote Bjarne Stroustrup, the god of C++:
> 
> "In C++, the definition of NULL is 0, so there is only an aesthetic difference.
> I prefer to avoid macros, so I use 0. Another problem with NULL is that people
> sometimes mistakenly believe that it is different from 0 and/or not an integer.
> In pre-standard code, NULL was/is sometimes defined to something unsuitable and
> therefore had/has to be avoided. That's less common these days."
> 
> ---->  http://www.research.att.com/~bs/bs_faq2.html#null
> 
> So as you can see, even the great Bjarne Stroustrup believes we don't need a
> 'null' keyword.
> 
> He also believes that garbage collection was never needed in C++, as
> std::auto_ptr<T> can handle everything.
> I don't fully agree with this...  But I can't really say he's wrong here either.
> 
> I guess my question is: What has D taken from this "so called" wisdom from a "so
> called" guru?
> 
> 

That's because of a _fault_ in C++, where you can compare pointers against numbers.. the consequence is that a null pointer becomes a 0 pointer.

But that's just silly, pointers are *not* numbers.
May 27, 2005
Pointers are numbers!

0x00000000 is the null pointer in C++, that's why we can use 0 instead of null. And Bjarne has stated that this hasn't changed on any machine that he knows of, and probably won't ever change.

If I have a pointer p (in C++) to an array of 3 ints, and p = 0xffffff20, then to access the second item in the array I can do:

int i = *(p + 1) // 0xffffff21

So if you can do arithmetic on pointers they must be numbers!  Right?

>
>That's because of a _fault_ in C++, where you can compare pointers against numbers.. the consequence is that a null pointer becomes a 0 pointer.
>
>But that's just silly, pointers are *not* numbers.


May 27, 2005
"Sam" <Sam_member@pathlink.com> wrote in message news:d75g34$6eb$1@digitaldaemon.com...
>
> Should I use NULL or 0?
>
> To quote Bjarne Stroustrup, the god of C++:

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1488.pdf


May 27, 2005
Sam wrote:
> Pointers are numbers!

Physically: yes. Conceptually: no.


-- 
Tomasz Stachowiak  /+ a.k.a. h3r3tic +/
May 27, 2005
"Ben Hinkle" <ben.hinkle@gmail.com> wrote in message news:d75oct$chc$1@digitaldaemon.com...
>
> "Sam" <Sam_member@pathlink.com> wrote in message news:d75g34$6eb$1@digitaldaemon.com...
>>
>> Should I use NULL or 0?
>>
>> To quote Bjarne Stroustrup, the god of C++:
>
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1488.pdf
>

oops - didn't see Sean had already linked to that. sorry!


May 27, 2005
I guess you're right there, but that's pointers.
D also has references, and I think you can't do arithmetic on references.
Pointers are kinda low level, but references are not so low, if I'm not wrong,
references are a higher level abstraction of pointers, where they are no longer
memory addresses, but object references. They encapsulate the concept of a
reference, and hide the concept of memorry addresses.

In article <d75o3q$caa$1@digitaldaemon.com>, Sam says...
>
>
>Pointers are numbers!
>
>0x00000000 is the null pointer in C++, that's why we can use 0 instead of null. And Bjarne has stated that this hasn't changed on any machine that he knows of, and probably won't ever change.
>
>If I have a pointer p (in C++) to an array of 3 ints, and p = 0xffffff20, then to access the second item in the array I can do:
>
>int i = *(p + 1) // 0xffffff21
>
>So if you can do arithmetic on pointers they must be numbers!  Right?
>
>>
>>That's because of a _fault_ in C++, where you can compare pointers against numbers.. the consequence is that a null pointer becomes a 0 pointer.
>>
>>But that's just silly, pointers are *not* numbers.
>
>


May 27, 2005
"Sam" <Sam_member@pathlink.com> wrote in message news:d75g34$6eb$1@digitaldaemon.com...

This is .. quite simply the most inane argument I've seen anyone make on any forum or NG in a long time.  The last time I saw something this crazy, someone was arguing over the proper name for a style of 3d shading, and he was arguing the wrong name.

You want to remove something as simple, innocuous, and commonly-used as the "null" keyword?

What would you do if "null" weren't a keyword?  I'm sure there's a lot of opportunity opened up for variable and function names by removing that pesky restriction.

You said something about "the fewer keywords a language has, the easier it is to learn."  That is .. the second most inane argument I've ever heard. The number of keywords has nothing to do with the programming style, runtime library, under-the-hood functionality, structure, or overall complexity of the language.  "true," "false," and "null" are simply there to increase readability, and because it conceptually makes no sense to compare a class reference to 0.  New programmers shouldn't have to understand the underlying concepts of memory addresses in a language like D, and shouldn't have to know that address 0 means "nothing."  If anything, having "null" makes it easier to learn the language.

You know what I can't stand?  That pesky "if" keyword.  Why can't we just use the ?: operator everywhere?  The fewer keywords, the easier, right?  :P


« First   ‹ Prev
1 2 3