Thread overview | |||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
June 08, 2002 null == 0 | ||||
---|---|---|---|---|
| ||||
Is there some reason why C++'s equivalence of NULL and 0 was considered not a good idea? In porting C++ to D, I end up having to change a lot of 0's to null. Just wondering if there's some reason for it or if it's just an oversight. It would sure be convenient. Sean |
June 08, 2002 Re: null == 0 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean L. Palmer | It could be that it is much better for maintenance. As in if(monitor == null) // clearly a pointer/reference if(monitor == 0) // clearly integral if(monitor) // boolean (or should be!) "Sean L. Palmer" <seanpalmer@earthlink.net> wrote in message news:adu1ee$1fmj$1@digitaldaemon.com... > Is there some reason why C++'s equivalence of NULL and 0 was considered not > a good idea? In porting C++ to D, I end up having to change a lot of 0's to > null. > > Just wondering if there's some reason for it or if it's just an oversight. It would sure be convenient. > > Sean > > |
June 08, 2002 Re: null == 0 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Matthew Wilson | I don't know what maintenance programmers have against using browse info to look up the declaration of a variable. When I'm maintaining code I don't like making that kind of assumption... I'll go look it up to make sure. Since D doesn't have separate headers, and doesn't need forward declaration, it keeps definitions closer to their usage point most of the time. That helps. Sean "Matthew Wilson" <dmd@synesis.com.au> wrote in message news:adu2ps$1gtv$1@digitaldaemon.com... > It could be that it is much better for maintenance. > > As in > > if(monitor == null) // clearly a pointer/reference > > if(monitor == 0) // clearly integral > > if(monitor) // boolean (or should be!) > > > > > > "Sean L. Palmer" <seanpalmer@earthlink.net> wrote in message news:adu1ee$1fmj$1@digitaldaemon.com... > > Is there some reason why C++'s equivalence of NULL and 0 was considered > not > > a good idea? In porting C++ to D, I end up having to change a lot of 0's > to > > null. > > > > Just wondering if there's some reason for it or if it's just an oversight. > > It would sure be convenient. > > > > Sean > > > > > > |
June 08, 2002 Re: null == 0 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean L. Palmer | What if you're using browse info? What if (as is common) you're reading the code on the train between clients? Surely if there's a way to make something definitive without an onerous imposition (and here's where we will all debate endlessly) on the original author, it's worth doing. Java is criticised and often quoted as an example of an overly patriarchal language, but it is far simpler to maintain (at least in the regard in which we are discussing) than other languages - Java just sucks for a lot of other reasons. "Sean L. Palmer" <seanpalmer@earthlink.net> wrote in message news:adu3f4$1hh4$1@digitaldaemon.com... > I don't know what maintenance programmers have against using browse info to > look up the declaration of a variable. When I'm maintaining code I don't like making that kind of assumption... I'll go look it up to make sure. > > Since D doesn't have separate headers, and doesn't need forward declaration, > it keeps definitions closer to their usage point most of the time. That helps. > > Sean > > "Matthew Wilson" <dmd@synesis.com.au> wrote in message news:adu2ps$1gtv$1@digitaldaemon.com... > > It could be that it is much better for maintenance. > > > > As in > > > > if(monitor == null) // clearly a pointer/reference > > > > if(monitor == 0) // clearly integral > > > > if(monitor) // boolean (or should be!) > > > > > > > > > > > > "Sean L. Palmer" <seanpalmer@earthlink.net> wrote in message news:adu1ee$1fmj$1@digitaldaemon.com... > > > Is there some reason why C++'s equivalence of NULL and 0 was considered > > not > > > a good idea? In porting C++ to D, I end up having to change a lot of > 0's > > to > > > null. > > > > > > Just wondering if there's some reason for it or if it's just an > oversight. > > > It would sure be convenient. > > > > > > Sean > > > > > > > > > > > > |
June 09, 2002 Re: null == 0 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean L. Palmer | "Sean L. Palmer" <seanpalmer@earthlink.net> wrote in message news:adu1ee$1fmj$1@digitaldaemon.com... > Is there some reason why C++'s equivalence of NULL and 0 was considered not > a good idea? In porting C++ to D, I end up having to change a lot of 0's to > null. > > Just wondering if there's some reason for it or if it's just an oversight. It would sure be convenient. The idea is that there are some cases where the null pointer might not be 0. I remember this issue from the early C days. The other idea is for type safety, i.e. making it clear you're dealing with a null reference rather than a numerical 0. |
June 09, 2002 Re: null == 0 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | null != 0 - I like that idea (though don't know why yet ...) type-safety - I like that very much. Very wise. Does this mean that conditional expressions involving pointers will have to be boolean, ie if(p != null) rather than if(p) ? "Walter" <walter@digitalmars.com> wrote in message news:aduk1j$216b$2@digitaldaemon.com... > > "Sean L. Palmer" <seanpalmer@earthlink.net> wrote in message news:adu1ee$1fmj$1@digitaldaemon.com... > > Is there some reason why C++'s equivalence of NULL and 0 was considered > not > > a good idea? In porting C++ to D, I end up having to change a lot of 0's > to > > null. > > > > Just wondering if there's some reason for it or if it's just an oversight. > > It would sure be convenient. > > The idea is that there are some cases where the null pointer might not be 0. > I remember this issue from the early C days. > > The other idea is for type safety, i.e. making it clear you're dealing with > a null reference rather than a numerical 0. > > |
June 09, 2002 Re: null == 0 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | "Walter" <walter@digitalmars.com> wrote in message news:aduk1j$216b$2@digitaldaemon.com... > > "Sean L. Palmer" <seanpalmer@earthlink.net> wrote in message news:adu1ee$1fmj$1@digitaldaemon.com... > > Is there some reason why C++'s equivalence of NULL and 0 was considered > not > > a good idea? In porting C++ to D, I end up having to change a lot of 0's > to > > null. > > > > Just wondering if there's some reason for it or if it's just an oversight. > > It would sure be convenient. > > The idea is that there are some cases where the null pointer might not be 0. > I remember this issue from the early C days. The language can always insert extra code there to swap null handle values when comparing (how often do you compare resource handles anyway?) Can the concept of "resource handle" be baked into the language any better than it is now? > The other idea is for type safety, i.e. making it clear you're dealing with > a null reference rather than a numerical 0. I agree with your points. It's not a major issue... just a C++ porting issue then. ;( Unfortunately as someone who has written a lot of C++ code I'm pretty deeply entrenched in the language. I like null better than NULL anyhow since it is the same case as all the other object identifiers. hehe Sean |
June 09, 2002 Re: null == 0 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Matthew Wilson | That's the thing... it's a lot more typing. Three more characters. hehehe Sean "Matthew Wilson" <dmd@synesis.com.au> wrote in message news:adum9g$23bh$1@digitaldaemon.com... > null != 0 - I like that idea (though don't know why yet ...) > > type-safety - I like that very much. Very wise. Does this mean that conditional expressions involving pointers will have to be boolean, ie if(p > != null) rather than if(p) ? > > "Walter" <walter@digitalmars.com> wrote in message news:aduk1j$216b$2@digitaldaemon.com... > > > > "Sean L. Palmer" <seanpalmer@earthlink.net> wrote in message news:adu1ee$1fmj$1@digitaldaemon.com... > > > Is there some reason why C++'s equivalence of NULL and 0 was considered > > not > > > a good idea? In porting C++ to D, I end up having to change a lot of > 0's > > to > > > null. > > > > > > Just wondering if there's some reason for it or if it's just an > oversight. > > > It would sure be convenient. > > > > The idea is that there are some cases where the null pointer might not be > 0. > > I remember this issue from the early C days. > > > > The other idea is for type safety, i.e. making it clear you're dealing > with > > a null reference rather than a numerical 0. |
June 09, 2002 Re: null == 0 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Matthew Wilson | "Matthew Wilson" <dmd@synesis.com.au> wrote in message news:adum9g$23bh$1@digitaldaemon.com... > Very wise. Does this mean that > conditional expressions involving pointers will have to be boolean, ie if(p > != null) rather than if(p) ? I haven't bought into that yet <g>. I guess I like the shorthand too much. |
June 10, 2002 Re: null == 0 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean L. Palmer | "Sean L. Palmer" <seanpalmer@earthlink.net> wrote in message news:advb1o$2n7e$1@digitaldaemon.com... > It's not a major issue... just a C++ porting issue then. ;( Unfortunately > as someone who has written a lot of C++ code I'm pretty deeply entrenched in > the language. I've ported a lot of C++ code to D, I just do a global search/replace of NULL to null. > I like null better than NULL anyhow since it is the same case as all the other object identifiers. hehe Yes, exactly. In C it is uppercase by the convention that macro constants are upper case. |
Copyright © 1999-2021 by the D Language Foundation