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].
Posted Sep 3, 2018, 8:32 AM UTC
Very few values in your program actually need to be nullable, so you only need to check those places where they are. And you should be checking those places anyway!
Edit:
Note that you might be missing the important fact that you need some way for the compiler to remember that you've done the check. You can do this by pattern matching or flow-sensitive typing, for example. But yeah, this means you don't have to keep going back to check, which would be super annoying!
It's also a shame to see the level of negativity in the other comments. It's really useful to hear perspectives like this, because it helps us see how other people might misunderstand what we are doing, and can help improve our explanations. Let's be a little friendlier please! :)
Exactly this.
Having everything nullable by default, on the other hand, is exactly what makes it necessary to constantly check and recheck for null.
In languages where ‘nullabillity’ is encoded in the type system, you only need to check things that can actually be ‘null’, and you (generally) only need to check it once.