This is an oldie (I first heard it in the 80s) but is one of my all time favorites. While it can be told about any two classes of people it really applies to a lot of code I encounter:
A physicist is showing a thermos to her friend, a programmer.
"It's amazing", she said. "You put a cold drink inside and regardless of how hot it is outside the drink stays cold".
The programmer is suitably impressed.
"But that's not all", she continued. "You can put a *hot* drink inside and no matter how cold it is outside the drink stays hot".
Now the programmer is perplexed.
Plaintively he asks, "But how does it know?"
I think of this whenever I read code that contains a gratuitous state variable that explains the type or content of some data structure rather than make the data structure self-explaining. Even more annoying when it's a class.
Having to coordinate two variables is a recipe for bugs down the road. Seems like it should be a beginner's mistake but I see it all the time in "non beginner" code.
Having to coordinate two variables is a recipe for bugs down the road. Seems like it should be a beginner's mistake but I see it all the time in "non beginner" code.