|
|
|
|
|
by bajsejohannes
4807 days ago
|
|
I've worked with a code base in C++ where the code base would accumulate significant amounts of if (argumentX == null)
return null;
at the top of function signatures. It was just defensive programming. Maybe argumentX couldn't be null, but it would take time to figure that out (sometimes I did that, though). More code means harder to read and maintain, thus costing dollars.This would also be contagious: If a piece of code checks if X is null, you'll assume that X can be null, whether or not that's true. I'd certainly prefer to be able to reason about the code with the safe assumption that certain things cannot be null. |
|
You can do this, but if you want it to be maintainable, you'll also want to detail in the function comments this technical debt. If you don't, someone else will come along and see your sweet method (looking only at the comments) and use it where the input can be null.
Ex: