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

Guess: the compiler knows you forgot to check the "Nothing" case and will tell you.



Ah, I see. I was confused by Haskell not doing that by default... at least the last time I wrote code on it.

Is there actual data that says that null pointers are actually causing bugs in production software? I always thought they are just a symptom of lazy programmers, and no language can fully protect against that.

Witness my awesome Haskell snippet of code:

foo (Just x) = x+2 foo Nothing = undefined

Ok, so it's somewhat better since the lazyness is now explicit and cannot happen so accidentally.


http://www.computerworld.com.au/article/261958/a-z_programmi...

Anders estimates 50% of the bugs in C# and Java are due to null dereferences.

Your example illustrates the unsafety of undefined, not the unsafety of nulls/Nothing. And you can of course grep for use of partiality in Haskell code and get warnings about partiality in your own functions.

I've seen NULL causing a lot of trouble in production in every setting I've been.

It is very rare to see people mis-handling a Maybe value in Haskell, simply because you have to be explicit about ignoring the Nothing case.

Also, in Haskell, if you get a Maybe value it is a very clear indication that the Nothing case actually exists and you have to handle it. In C, C#, Java, Go, when you get a reference, it is unclear whether it could be null or not in practice. Checking for null when it isn't warranted is dead code you never test. Avoiding checking for null risks missing checks in cases you actually need to check. All of this is simply not a problem when the types don't lie.


"Is there actual data that says that null pointers are actually causing bugs in production software?"

Have you ever written even one line of code in your life?


This comment really clashes with your user name =P




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

Search: