digitalmars.D - Bjarne Stroustrup takes issue with the 'null' keyword
- Sam (15/15) May 26 2005 Should I use NULL or 0?
- Brad Beveridge (8/13) May 26 2005 Well, I get the impression that many people interested in D think that
- Sean Kelly (19/34) May 26 2005 FWIW, here is a bit from the C++ standard that discusses NULL:
- Walter (5/10) May 26 2005 language
- Hasan Aljudy (5/28) May 26 2005 That's because of a _fault_ in C++, where you can compare pointers
- Sam (8/12) May 26 2005 Pointers are numbers!
- Tom S (4/5) May 26 2005 Physically: yes. Conceptually: no.
- Hasan Aljudy (7/21) May 26 2005 I guess you're right there, but that's pointers.
- Matthias Becker (10/18) May 27 2005 Well, text is represented as numbers as well. But it's stupid to think a...
- Ben Hinkle (3/5) May 26 2005 http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1488.pdf
- Ben Hinkle (3/10) May 26 2005 oops - didn't see Sean had already linked to that. sorry!
- Matthias Becker (3/10) May 27 2005 or
-
Jarrett Billingsley
(23/23)
May 26 2005
"Sam"
wrote in message - Ben Hinkle (1/4) May 26 2005 yeah! - now you're gettin' in the spirit!
- clayasaurus (2/10) May 26 2005 and we can replace for, foreach, and while loops with goto :P
- Kris (5/9) May 26 2005 You know what bothers me? All those darned extra button on this keyboar...
- Derek Parnell (11/16) May 26 2005 I once used a notation that went a bit like this ...
- Chris Sauls (11/19) May 26 2005 Looks semi-Lisp-ish... or maybe Guile/Scheme... what on earth was/is it?...
- Derek Parnell (16/27) May 26 2005 [embarrased]
- Chris Sauls (6/13) May 26 2005 Ahh.. so 'f' contained an "arbitrary" expression to be evaluated in
- Hasan Aljudy (4/34) May 26 2005 hmm ..
- <t t.com> (6/10) May 27 2005 Those who do not know Lisp are condemned to repeat it. :)
- Hasan Aljudy (7/30) May 26 2005 As Sean Kelly pointed out, your Bjarne Stroustrup thinks it's a good
- Dejan Lekic (12/12) May 27 2005 With all due respect sir, as a programmer with more than 13 years of wor...
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
"Sean Kelly" <sean f4.ca> wrote in message news:d75jdf$930$1 digitaldaemon.com...If that isn't enough, Bjarne Stroustrup and Herb Sutter proposed alanguageextension 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). Inshort,I think there's ample support for the existence of 'null' in D :)Some day, C++ will catch up with D <g>.
May 26 2005
Not if DMD doesnt build decent debug info it wont. Im very dissappointed that you still cant view members & globals whilst debugging executables. At least C++ has excellent debugging support. In article <d75uqd$i6n$1 digitaldaemon.com>, Walter says..."Sean Kelly" <sean f4.ca> wrote in message news:d75jdf$930$1 digitaldaemon.com...If that isn't enough, Bjarne Stroustrup and Herb Sutter proposed alanguageextension 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). Inshort,I think there's ample support for the existence of 'null' in D :)Some day, C++ will catch up with D <g>.
May 27 2005
"Walter" <newshound digitalmars.com> wrote in message news:d75uqd$i6n$1 digitaldaemon.com..."Sean Kelly" <sean f4.ca> wrote in message news:d75jdf$930$1 digitaldaemon.com...It already did, several years ago: #include <stlsoft_nulldef.h>If that isn't enough, Bjarne Stroustrup and Herb Sutter proposed alanguageextension 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). Inshort,I think there's ample support for the existence of 'null' in D :)Some day, C++ will catch up with D <g>.
May 27 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 26 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 26 2005
Sam wrote:Pointers are numbers!Physically: yes. Conceptually: no. -- Tomasz Stachowiak /+ a.k.a. h3r3tic +/
May 26 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 26 2005
Pointers are numbers!Well, text is represented as numbers as well. But it's stupid to think about text as numbers. Instead you should simply read it as text. So you should think about pointers as something that stores positions of objects not as 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?Wrong. pointer + pointer => error If you can't even add them you can't say they are numbers (ever seen a number that can't be added to another one? There are even languages that allow things like string * number to repeat a string several times. So are strings numbers? I don't think so.
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 26 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...oops - didn't see Sean had already linked to that. sorry!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 26 2005
In article <d75oct$chc$1 digitaldaemon.com>, Ben Hinkle says..."Sam" <Sam_member pathlink.com> wrote in message news:d75g34$6eb$1 digitaldaemon.com...or http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1601.pdfShould 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" <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
May 26 2005
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? :Pyeah! - now you're gettin' in the spirit!
May 26 2005
Ben Hinkle wrote:and we can replace for, foreach, and while loops with goto :PYou 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? :Pyeah! - now you're gettin' in the spirit!
May 26 2005
You know what bothers me? All those darned extra button on this keyboard thingy ... why can't we program using only the space-bar and ctrl-key? "Ben Hinkle" <ben.hinkle gmail.com> wrote in message news:d75ug9$i2a$1 digitaldaemon.com...justYou know what I can't stand? That pesky "if" keyword. Why can't weuse the ?: operator everywhere? The fewer keywords, the easier, right? :Pyeah! - now you're gettin' in the spirit!
May 26 2005
On Thu, 26 May 2005 21:52:07 -0400, Ben Hinkle wrote:I once used a notation that went a bit like this ... (? name = "derek" <T> (amt := 10) <F> (amt := 1) ) Weird at first, but I got used to it quickly. -- Derek Melbourne, Australia 27/05/2005 12:14:06 PMYou 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? :Pyeah! - now you're gettin' in the spirit!
May 26 2005
Derek Parnell wrote:I once used a notation that went a bit like this ... (? name = "derek" <T> (amt := 10) <F> (amt := 1) ) Weird at first, but I got used to it quickly.Looks semi-Lisp-ish... or maybe Guile/Scheme... what on earth was/is it? Although I did once use something similar: And yes that period (.) does go at the end... and if either of the clauses, seperated by a semi-colon (;) had multiple statements... they were seperated by a comma (,)... cute, huh? I think demons invented it. -- Chris Sauls
May 26 2005
On Thu, 26 May 2005 21:33:14 -0500, Chris Sauls wrote:Derek Parnell wrote:[embarrased] It was a simple scripting language that I developed when working with IBM 360 mainframes back in the 1970s. I was playing around with Lisp, PL/I, Fortran, and Autocoder then. Seemed like a good idea at the time ;-) It could do really bad stuff ... (? amt < lt 10 > ( f := '+= 10') ; add 10 when < 10 < le 20 > ( f := '+= 1') ; add 1 when between 10 and 20 < > ( f := '+= 5') ; otherwise add 5 ) (amt $f) ; apply formula -- Derek Melbourne, Australia 27/05/2005 12:31:39 PMI once used a notation that went a bit like this ... (? name = "derek" <T> (amt := 10) <F> (amt := 1) ) Weird at first, but I got used to it quickly.Looks semi-Lisp-ish... or maybe Guile/Scheme... what on earth was/is it?
May 26 2005
Derek Parnell wrote:(? amt < lt 10 > ( f := '+= 10') ; add 10 when < 10 < le 20 > ( f := '+= 1') ; add 1 when between 10 and 20 < > ( f := '+= 5') ; otherwise add 5 ) (amt $f) ; apply formulaAhh.. so 'f' contained an "arbitrary" expression to be evaluated in terms of a variable via a '(xxx $f)' expression... creative. As a friend of mine once said of one of his student's code... "Cute. Not wise... but cute." :) *steals the idea* -- Chris Sauls
May 26 2005
Jarrett Billingsley wrote:"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? :Phmm .. is that a ternary operator usage? :P // <<-- same here
May 26 2005
In article <d75rh5$fg2$1 digitaldaemon.com>, kb3ctd2 yahoo.com says..."Sam" <Sam_member pathlink.com> wrote in message news:d75g34$6eb$1 digitaldaemon.com... 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? :PThose who do not know Lisp are condemned to repeat it. :) ( in lisp the 'if' function is 'ternary' (and many other functional languages ( can be used in conjuction with map and reduce ( 'jus sayin' is all ) ) ) ) - Factory
May 27 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?As Sean Kelly pointed out, your Bjarne Stroustrup thinks it's a good idea to introduce a "null" keyword in C++. except that he's naming it "nullptr", and he's only doing that to avoid name conflicts .. because many people are using "null" already. hmm .. the mistake of no implementing "null" in the first place, caused him to choose a less clean name, "nullptr" ..
May 26 2005
With all due respect sir, as a programmer with more than 13 years of working experience (10 in C/C++ fields), I must say that your "Bjarne-god story" is not for this newsgroup (i do not want to use some "bad words" actually)... Think about D as a mix of all goods from all modern languages, and some original ideas. Depending on level of type-safety You want NULL can be treated differently. I personally like D's approach. -- ........... Dejan Lekic http://dejan.lekic.org
May 27 2005