For some reason you always end up with a NPE when you least of all need it.
The problem with NPE is usually that you can see WHEN you use the object that somebody has provided the WRONG information earlier on. NPE always means trying to trace backwards in the code, and find suspects, and that is not always possible.
Imagine a simple attribute on a class (say name). You will see NPE when it is USED, not when it is ASSIGNED. Yet, the problem is the assignment, not the use.
In some of the many JVM languages and suggestions, there are occassionally the brilliant idea of null-safe types, but some of them relates mostly to USAGE, not ASSIGNMENT.
I still work mostly in Java, and have to write (and advocate for) defensive assignment styles to avoid this problem (in attributes and parameters).
Some attributes/parameters have a legal right to contain null (This could actually be less than you think), and so we try to establish a contract of WHEN these CAN contain null. With the rest we reserve the right to fail fast. The earlier the better..
This view point is not really agile. It's pragmatic. And there is no reason why we haven't learned anything since the arrival of the Java language.
0 comments:
Post a Comment