Hacker News new | past | comments | ask | show | jobs | submit login

   > ...which immediately tells you to go fix the code.
Assuming your code isn't deeply nested. I've seen cases where null was triggered years after code went into production. In that case you have to:

A) Assume value isn't null and have more readable code

B) Litter the code with null checks.

e.g.

    if (a.getStuff().getValue() == "TEST")
becomes

    if (a != null && a.getStuff() != null && a.getStuff().getValue() == "TEST)

Thing with Maybe/Optional you have to check for presence of None, otherwise your code won't compile. Another smart way is what C# did. Integer can't be null. Integer? can be null.



But expanded null checks could be automated by the compiler if so desired right? Without having to change the nature of null into an optional.

@MAYBE if(a.getStuff().getValue() == "TEST")


You could check every value for null, sure. But a) why would you want to? (and wouldn't it be bad for performance) and b) how would you handle it? Knowing that a value somewhere in your program was null doesn't really help you any.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: