Jump to page: 1 2
Thread overview
Why is null lowercase?
Jan 24, 2013
Matthew Caron
Jan 24, 2013
bearophile
Jan 27, 2013
Phil Lavoie
Jan 24, 2013
Mike Parker
Jan 24, 2013
monarch_dodra
Jan 24, 2013
Rob T
Jan 24, 2013
Matthew Caron
Jan 25, 2013
Ali Çehreli
Jan 25, 2013
Don
Jan 25, 2013
Ali Çehreli
Jan 25, 2013
Era Scarecrow
Jan 25, 2013
Ali Çehreli
Jan 25, 2013
Era Scarecrow
Jan 25, 2013
Maxim Fomin
Jan 27, 2013
Phil Lavoie
Jan 24, 2013
Ali Çehreli
Jan 24, 2013
Matthew Caron
January 24, 2013
This is probably a question for Walter, but maybe others know.

Of all of the differences between C and D, the one which I have the most difficulty adapting to is null being lowercase. Does anyone know why this decision was made?
-- 
Matthew Caron, Software Build Engineer
Sixnet, a Red Lion business | www.sixnet.com
+1 (518) 877-5173 x138 office
January 24, 2013
Matthew Caron:

> Of all of the differences between C and D, the one which I have the most difficulty adapting to is null being lowercase. Does anyone know why this decision was made?

Probably because writing all in uppercase ugly. null is a keyword like the others, and they are in lowercase. DO YOU PREFER A LANGUAGE ALL IN UPPERCASE?

Bye,
bearophile
January 24, 2013
On Thursday, 24 January 2013 at 12:56:03 UTC, Matthew Caron wrote:
> This is probably a question for Walter, but maybe others know.
>
> Of all of the differences between C and D, the one which I have the most difficulty adapting to is null being lowercase. Does anyone know why this decision was made?

In the world of C and C++, 'NULL' is a macro. Macros, by convention, are all uppercase. Contrast that with C++11 which provides for 'nullptr', a type rather than a macro. Consider Java, which also has a lowercase null. In D, null follows the same convention as other built-ins, so it is lowercase. To me, it makes perfect sense. There are no macros in D, so I wouldn't have expected to see NULL to begin with. *That* would have been highly inconsistent.
January 24, 2013
On Thursday, 24 January 2013 at 12:56:03 UTC, Matthew Caron wrote:
> This is probably a question for Walter, but maybe others know.
>
> Of all of the differences between C and D, the one which I have the most difficulty adapting to is null being lowercase. Does anyone know why this decision was made?

Keep in mind that strictly speeking, "NULL" != "null":

NULL is a C macro that expands to 0.
null is a D keyword that cannot be implicitly cast to an integer.

This is a source of bugs:

//----
void foo(int);
void foo(int*);
//----

in C++:
foo(NULL); //Calls "void foo(int)"

in D:
foo(null); //Calls "void foo(int*)"

Having code that is valid in both C++ and D, but having a different behavior would be VERY bad.

--------
BTW, you can be thankful that it is *just* "null", because what it really is C++11's "null_ptr". Which is worst.
January 24, 2013
Hi,

In C, NULL is a #define, and #defines are typically all-caps. In D, null is real keyword recognized by the compiler, and those are typically lowercase. I am just guessing here, but I'd say the choice for 'null' instead of 'NULL' is just to be coherent with this.

Personally, I kinda like 'null'. :-)

LMB




On Thu, Jan 24, 2013 at 10:56 AM, Matthew Caron <matt.caron@redlion.net> wrote:
> This is probably a question for Walter, but maybe others know.
>
> Of all of the differences between C and D, the one which I have the most difficulty adapting to is null being lowercase. Does anyone know why this decision was made?
> --
> Matthew Caron, Software Build Engineer
> Sixnet, a Red Lion business | www.sixnet.com
> +1 (518) 877-5173 x138 office
January 24, 2013
On Thursday, 24 January 2013 at 12:56:03 UTC, Matthew Caron wrote:
> This is probably a question for Walter, but maybe others know.
>
> Of all of the differences between C and D, the one which I have the most difficulty adapting to is null being lowercase. Does anyone know why this decision was made?

You'll get used to it, it's actually much better than typing in NULL, and it's a real type instead on an int, which never worked well in C.

Just be warned that when checking for null *do not* use equality operator

if ( ptr == null) ...

instead use the identity operator "is"

if ( ptr is null) ...

for not null checks

if ( ptr !is null) ...

BTW, half of what you thought worked well in C/C++ will get turned upside down if you stick with D, and once you get it, moving back to C/C++ becomes unbearable.

--rt
January 24, 2013
On 01/24/2013 04:56 AM, Matthew Caron wrote:
> This is probably a question for Walter, but maybe others know.
>
> Of all of the differences between C and D, the one which I have the most
> difficulty adapting to is null being lowercase. Does anyone know why
> this decision was made?

Similarly, the common macros TRUE and FALSE are replaced by the 'true' and 'false' keywords.

Ali
January 24, 2013
On 01/24/2013 12:50 PM, Ali Çehreli wrote:
> Similarly, the common macros TRUE and FALSE are replaced by the 'true'
> and 'false' keywords.

Ironically, those don't bother me because I never used them.

-- 
Matthew Caron, Software Build Engineer
Sixnet, a Red Lion business | www.sixnet.com
+1 (518) 877-5173 x138 office
January 24, 2013
On 01/24/2013 12:04 PM, Rob T wrote:
> You'll get used to it, it's actually much better than typing in NULL,
> and it's a real type instead on an int, which never worked well in C.
>
> Just be warned that when checking for null *do not* use equality operator

Yeah, the compiler helped me find that one out. That takes a little getting used to as well. Old habits and such.

> for not null checks
>
> if ( ptr !is null) ...

And too much perl has me wanting to write:

if (ptr is not null)

> BTW, half of what you thought worked well in C/C++ will get turned
> upside down if you stick with D, and once you get it, moving back to
> C/C++ becomes unbearable.

It already is. I have very little desire to do anything in any other language. C and C++ are too primitive. Java and C# don't play as nicely with native libraries as I'd like and require a whole VM which consumes gobs of memory and takes forever to start. D gives me the features I want from Java and C# while falling somewhere between them and C in terms of speed. I can get more done, faster, in D.

Meanwhile, it seems like the rest of the world is moving towards writing everything in JavaScript, and that's just leaving me scratching my head in amazement.
-- 
Matthew Caron, Software Build Engineer
Sixnet, a Red Lion business | www.sixnet.com
+1 (518) 877-5173 x138 office
January 25, 2013
On 01/24/2013 12:42 PM, Matthew Caron wrote:

>> for not null checks
>>
>> if ( ptr !is null) ...
>
> And too much perl has me wanting to write:
>
> if (ptr is not null)

IIRC, the !is operator is thanks to bearophile. We would have to reverse the logic before he insisted on !is: :)

    if (!(ptr is null))

Ali

« First   ‹ Prev
1 2