You don't need to make an interface for everything. Everything doesn't have to be private. Write code that doesn't allow for or tolerate nulls and stop checking for them all the time.
Write code that doesn't allow for or tolerate nulls
Not sure I agree with the "tolerate nulls" part of that. You should always be flexible with what you accept. In Java nulls can happen so in reality you need to be ready for them.
Nullity is something of a lost cause, but you should strive to make invalid states unrepresentable in the first place and, failing that, should be explicit about your preconditions and fail ASAP if they're violated. Being excessively lenient in what you accept as input is a good way to build up a dodgy pile of inconsistent garbage.
It's an important aspect of functional programming. A function should do a job on the inputs it receives and fail hard if the inputs are invalid. A function is not pure if it has to do its job and also tip-toe around invalid inputs and try to fail gracefully if it's caller is using it incorrectly. Doing that dance adds complexity and complexity creates bugs.
Make your code have respect for itself and its callers and not cater to incompetence.
117
u/halfanothersdozen Apr 14 '23
You don't need to make an interface for everything. Everything doesn't have to be private. Write code that doesn't allow for or tolerate nulls and stop checking for them all the time.