Ian Hatch (wererogue) wrote,
Ian Hatch
wererogue

To null or to NULL?

I learned object oriented programming in Java. In Java, you specify that a variable of any kind (aside from basic types - int, for example) is unset by setting it to null. This sets the variable's internal reference to the data for that object to a special value which says "I am unset". This convention is used in C# and javascript, and probably a few others.

In C++, you can't unset a reference. However, you can use pointers, which are actual addresses of the memory location containing the data, and by convention, setting a pointer to 0 means it's unset. Universally, there is a label defined which is translated to 0 called NULL which makes code a lot easier to read.

Now, I'm perfectly used to NULL. I've worked with it every day for nearly 3 years now, and it's fine. However, I've just started work on a project at home in C#.

Initially, I was typing NULL in C#, which kind of made sense. After all, I haven't used Java for a long time. However, I soon got used to using null instead, probably because of the 5+ years of using it before I really got into C++.

Today at work I've been typing null all day!

As I type this out, I realise how incredibly dull it is. Too bad! I'm posting it anyway :P
Subscribe
  • Post a new comment

    Error

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 12 comments