|
|
|
|
|
by martinced
4913 days ago
|
|
Java is not identical to Obj-C but the 'null' fiasco is mindboggling... Back when the book *"Effective Java" came out, a truly great advice was to use empty arrays everywhere you could instead of null. The second enlightenment came to me when the smart brains at JetBrains decided to ship IntelliJ IDEA with the @NotNull annotation. I basically started to annotate as many methods returning something as @NotNull and then saw the number of NullPointerException go drastically down. It's not possible everywhere but once you start to think about it, you realize that you don't need nearly as many null references as you think you did. Then you started having IntelliJ IDEA warning you real-time (even on incomplete source file) about "reference xxx is never going to be null" (so the non-null check is pointless) or "warning: reference to xxx may be null". Great stuff. Years later there are still 99% of all the Java codebase not using the @NotNull annotation. Sad but true. Now of course other language's take on the subject are interesting too: the maybe monad, the way Clojure deals with empty / nil sequences, etc. |
|
Null as a valid value for every reference type by default is brain-dead.
It is one of my major gripes with modern C#.