Programming Proverbs 17: Never assume the computer assumes anything

The computer doesn’t know what you mean, it only knows what you tell it. How often do we tell people that? Pretty often if I am any indication. And yet people do assume all the time. They assume that variables will be cleared out by the system before being used. In some languages they are and in some they are not. Should you really take the chance? I think not.

does the computer assume you want an expression evaluated in one direction? It’s going to do it in one direction but you can’t assume that it assumes you want this one done differently. That is what parentheses are for.

The computer is not going to assume that just because you declare and array of objects that you want an object instantiated for each element. If you want and element you need to say so.

I used to describe the computer as an annoying little sibling that takes everything you say literally and will go out of its way to ignore assumptions and translate any ambiguity incorrectly. It may not be strictly true but it is a safer attitude to have then assuming it knows what you want and wants to help.

This is the seventeenth of a series of posts based on the book Programming Proverbs by Henry Ledgard. The index for the series is an earlier post and discussion of the list as a whole is taking place in the comments there. Comments on this “proverb” are of course very welcome here.