Did Java do us a favour, or no?
Gripe of the day alert!
In the old days, when I was a C programmer (when we were all C programmers), reading a null pointer was just about the worst thing you could do, apart from perhaps writing to one. Then along came Java – in many ways much nicer, it has a NullPointerException, so your program prints a nice message and doesn’t just core dump.
My gripe is that this fact has made people lazy. Whereas I used to be completely anal about checking pointers in C, I’ve become much more relaxed. I’ve noticed this laziness in my code recently and I’m going to change because…
A NullPointerException is not acceptable, EVER! (In my opinion of course). I hate getting them, whether in commercial software, in open-source software, in free software, or in my software. It tells you something is badly wrong, but rarely gives a user any insight into which of the million parameters that affect the running of the software is to blame.
One well-respected piece of open-source software was NPEing all over me recently and it was “right wracking me off”. Yes, I know I was fiddling around with it trying to get something obscure to work, and when I found out how to make it work, it didn’t NPE, but a well written piece of software doesn’t NPE, and if you’re calling an exposed API, then that API should be ultra-defensive.