"Don't assume anything".
So many times when shit hit the bricks because someone assumed something about some other thing they clearly don't know everything about. Which eventually lead to the system failing.
"Don't assume anything".
So many times when shit hit the bricks because someone assumed something about some other thing they clearly don't know everything about. Which eventually lead to the system failing.
I don't have 20 years of experience yet. But my PoV is as follows: assume as much as you can and ensure that if those assumptions are broken, you have fail-fast-and-log triggers (when it's possible). So when that trigger hits, you'll understand what assumption is broken. For example in Java I'll write Objects.requireNonNull(x, "x") and move on. If that assumption is broken, I'll have stack trace in my logs and I'll write additional logic. It won't take much time. But if that assumption will not be broken, I just saved few hours of time and few dozens of LoC from future maintenance.
Some people hate NullPointerExceptions and want to get rid of them. I love them. They're incredibly useful for me.
This is not a blind assumption that you make, but one based on lots of evidence (for example you are aware of the testing procedures and QA processes of the CPU manufacture, and you are aware that millions of people and companies use the same CPU model as you and if there were bugs they would have detected them).
If you were to buy some CPU that someone shady made themselves in their basement, them you would probably not make the assumption that the CPU works.
A lot of times programmers make assumptions without properly verifying that the assumption is true, and that is when problems happen. for example, when working with a library function, the programmer might test that it works with certain types of inputs and then just assume that it also works with other types, without actually checking the documentation or verifying
You are doing exactly that, assuming nothing. The number of times I've seem "meh, x can't be null here, just do nothing about it" (instead of some way of asserting that assumption, such as you provide) is staggering.
They don't mean that you just silently ignore the null value, they mean that they would prefer to use a language that has proper optional types.
This attitude belies the fact that of the 1000s of assumptions you make every day 1 or 2 will end up being incorrect, but it's usually very, very hard or even impossible to know which in advance.
One who doesnt make assumptions at all just wouldnt do anything, though.
(For clarity's sake: Not disagreeing at all, just illustrating your point with a reductio ad absurdum example.)