3 ms·
The article asserts that authors are not testing their code. The problem is that you can't ensure that every possible bug is exercised in tests. Think of the
by DannyB2 10y ago
The article asserts that authors are not testing their code. The problem is that you can't ensure that every possible bug is exercised in tests. Think of the static typing of the compiler as the very first level of testing. If you can have an NPE at this line of code, then it won't compile. The programmer is forced to deal with it. It has failed the first round of 'testing' done by the compiler.
Who's job is it, the programmer or the language?
In this case, it is the programmer, who is being forced to fix it by the language. We don't want code with bugs. Don't 'fix' it in testing when it is way cheaper to put that null test into the code when it is written. The compiler can absolutely ensure that no NPEs can be generated. The testing absolutely CAN NOT make this guarantee.
There are other languages that allow sloppy programming. Use them if you like. Encourage their use if you like. If there were one perfect programming language then everyone would be using it already.