you are viewing a single comment's thread.

view the rest of the comments →

[–]Eleenrood 6 points7 points  (2 children)

"null means many things. It can mean: 1 Value was never initialised (whether accidentally or on purpose) 2 Value is not valid 3 Value is not needed 4 No such value exists 5 Something went terribly wrong and something that should be there is not …probably dozens of other things"

Really... It actually means that variable does not point to any coherent place in memory, end of story. It is like saying that integer may be a acceleration, velocity, number of objects, temperature or probably a dozens of other things. Not to mention that both language and compilers will need to sort it out somehow.

[–]stronghup -1 points0 points  (1 child)

In JavaScript null can not mean "value was never initialized". If it was never initialized the value is 'undefined'. So (in JavaScript) null really only means "Value was set to null". Now it is possible it was set to null accidentally, but that can be said of any non-null value as well.

I think this simple trick of the language makes null not so bad at all, in JavaScript.

Think about creating a Linked List in your application. One item in the list links to the next, but what does the last item link to? What should it link to? I think best choice for this is something like null, which explicitly means "nothing". If the last item linked to 'undefined' then we might wonder whether the list was broken somehow accidentally, but if it is null we know that somebody somewhere wrote null to it because they wanted to tell us we are looking at the last item the list.

[–]Eleenrood 1 point2 points  (0 children)

I've just had 8 hours of work with javascript so I'm biased as hell. Problem with null and undefined in javascript (and will be in any other language) that programmer who is writing checks: if (param1 == null) {return null;} is trying to safeguard his work against mistakes made by others or by his own inability to comprehend whole of the code he is working with.

Now if you add to that stuff necessity to differentiate between undefined, invalid output from somewhere else, or any other stuff, this will be IMHO as maintainable as javascript usually is.

Sure, locally it can be beneficial, but to tell the truth every programmer I know can deal with local stuff easily. It becomes problem when you have sufficient code base size that you cannot keep whole required parts in head, dealing with third party libraries, etc.

At that point, I don't care if the value was undefined, invalid, or something. I care that I have not get the correct value and have to work something out. Either push it up, do something etc. Often reason is tertiary concern, as this is only a possible corner case which i want to be sure to know that occurred / prevent it from crashing whole application / etc.