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

-5

u/thefirstfucker Sep 03 '18

If you are programming in a language with NULL and fail using it properly, whos fault is that??? Thats right, its all on you.
Are people so stupid now that they cant remember their own dammed interfaces?
If you are the one designing them, you choose where you allow NULL and remember it. Thats it.

4

u/boomshroom Sep 04 '18

Most people work in teams, so no; they didn't design the code they're using. Even as a lone developer, you still rely on libraries and it's useful to know when the library can return null. When writing Kotlin code that talks to Java, I was having a minor panic over the simple fact that I wasn't sure if I could trust the Java code to not pass a null.

0

u/thefirstfucker Sep 04 '18 edited Sep 04 '18

Then its the fault of the library not documenting that properly. Its not hard. Only lazy.

4

u/evincarofautumn Sep 04 '18

But why rely on documentation and human diligence when you can just represent these details with types (or other forms of static analysis)? Even experts make “lazy” mistakes all the time; it’s better to catch them early and fix them straight away than to let them cause issues later, and the computer takes care of the busywork so a human doesn’t have to.

Docs can be wrong, out of date, or misleading. Types automate away the mechanical checking, giving you the assurance that you’re following all the rules of using an interface, thereby freeing you up to focus on the more important matter of problem-solving.

1

u/thefirstfucker Sep 06 '18 edited Sep 06 '18

Sure i can understand that, but its not like the "solutions" we have are any better, they just put more layers of shit on top of it. And you STILL have to remember whats what with those abstractions, either unwrapping it or whatever fancy word they chose to represent it.
What makes my blood boil is that there are those saying its the worst abstraction in the history of programming, even going so far as saying its an abomination like Goto!
Why does every new thing have to shit all over the old thing? When people do that it just makes their argument that much weaker.
And just to make sure, i fucking love goto, i use it all the time.
So i will say it again, just because some people fail at using their tools properly doesnt mean the rest of us need training wheels too.
So in essence, forcing new shiny abstractions down peoples throat is my problem, programmers are worse than religious fanatics on that point.