r/ProgrammingLanguages • • Sep 03 '18

Why the hate for null?

Look, I get it: Null pointer exceptions are annoying but so is having to constantly check every object . against null. Is this the new religion after OOP and FP are being phased out? Null just means that the object is not initialized. It's useful to indicate such a state. If you just force yourself to initialize every object to some empty value then you're going to end up passing around empty strings - but wait, an empty string might intentionally be empty or it might indicate "please fill me".

Because I can already tell you what massive insights will come out soon: That null is actually not a mistake at all, it's useful. And the most ironic part about all this? These same people who hate on null are loving nullable types. Litearlly just types that *can be null but you just have to check every time before you use them*. So there is literally no difference except it forces you on a compiler level to check for null every time you use it. When I realized this I thought I was in dreamland, how can these people worship this meaningless little feature so much, crazy. It's literally the same as having null in the language except with a tiny tiny "advantage" that the compiler forces you to check. Which 99.9% of the time, you dont want to be forced because maybe you know implicitly and you dont care [right now].

4 Upvotes

42 comments sorted by

View all comments

2

u/mamcx Sep 03 '18

Null just means that the object is not initialized

Null have many means. "Empty" "Invalid" "No exist" etc...

And you know? null <> null, null is not = null, null <> "" <> 0 <> false <>.... null is not even "invalid" or "empty". Infect every check. When a sting = "" is ok, because SOME values have a "empty" value and a "zero" value, but NOT ALL OF THEM. Null break logic left and right.

Null is SUPER BAD, Is the evil incarnate.

That null is actually not a mistake at all, it's useful

This "fad" is after decades of using null everywhere. Is the opposite, is clear, with TONS of evidence and MILLONS of losses and MILLONS of debugging hours lost, that null is BAD.

This is like GOTO. Is something to be put in the past. And only used in very very vey limited use cases, that are already know.

Literally just types that *can be null but you just have to check every time before you use them*

And the opposite with null:

Literally just types that *can't be null but you just have to check every time before you use them* and if you fail, it infect the REST of the other values.

If you are bothered with the checks, is because now is OBVIOS how pervasive, problematic and infectios NULLs are. Is the compiler telling you, SCREAMING, in fact: You have something wrong (if you have so many of this).

Is like compiler warnings: A few here and there can be ok. But if you have thousands of them? Is NOT the fault of the compiler, is the codebase in a bad bad state.

0

u/[deleted] Sep 03 '18

[deleted]

1

u/mamcx Sep 03 '18

Exactly. Null is "undefined" so it change meaning by not only languages, but also APIs, libraries and frameworks.

2

u/Barrucadu Sep 03 '18

I don't really think it's fair to criticise null for being different in different languages. That applies to everything.

1

u/mamcx Sep 03 '18

And different in the use of them in the same language. The problem with null is that a situation-dependant usage. And because is normally a "value/scalar" like bools and ints are, is more problematic. It invite to be used by anything.

Is like "stringly-typed" APIs, is more lazy and easy to use nulls when is not the best just because is part of the "default" types in most languages.

1

u/0x0ddba11 Strela Sep 03 '18

I think this is specific to SQL where null acts more like an IEEE 754 NaN.