In your journey as a software developer, have you ever encountered a difficult problem that you couldn’t solve? And then, in a flash of insight, a potential solution occurs to you! You joyfully code it up and behold, it works!
There’s a problem, though. The performance is abysmal. Or you had to violate good practice to get your code to work, like working with global variables or some bothersome dependency. Your code smells like all the herring in the world laid end-to-end across the Sahara Desert.
You know something is wrong, so you try to think of other solutions. Nothing suggests itself. You just accept that, flawed as it is, this is the only possible solution.
Then a more senior programmer reviews your code and not only points out all your faults, but suggests a simpler, more performant solution that was right in front of you the whole time. The better code is obvious in hindsight, but when you were writing the code, you didn’t see any of that.
You, my friend, have fallen victim to a cognitive trap that psychologists have dubbed the “Einstellung effect”.
The Einstellung effect, from the German word for “mindset, is a cognitive phenomenon that occurs when you get stuck on a solution to a problem and you are incapable of considering alternatives. According to Barbara Oakley in A Mind for Numbers, “an idea you already have in mind, or your simple initial thought, prevents a better idea or solution from being found.”
As a novice and junior programmer, I fell victim to the Einstellung effect on several occasions. However, cognitive research indicates that experts fall into this trap just as often and may be even be more prone to Einstellung than novices.
Psychologists do not know the precise cause of the Einstellung effect, but their studies seem to indicate that once we glom onto a familiar solution, a sort of blindness sets in. In experiments with chess players of all skill levels, from grandmasters down to amateurs, a majority of the players identified a familiar “checkmate in five moves” scenario while totally missing a “checkmate in three moves” on the same board. The psychologists tracked the eye movements of the players and discovered that once the players identified the 5-move scenario, THEIR EYES NEVER MOVED FROM THOSE SQUARES, despite their protestations that they were scanning the board for other solutions.
In effect, the players, once they spotted their familiar solution, were blind! They literally could not see any alternatives. I’ve experienced a similar kind of blindness when looking for something in the garage that I thought was in a red container when, in fact it was in a white one. We see what we are looking for. I will even pick up the white container to see if the red container is behind it.
In the chess experiments, and others, such as the famous water jugs problem, the spell was broken for many people (over half!) if the cognitive scientist running the experiment gave them a hint, such as “Don’t be blind!” This seems to indicate there are ways to avoid or mitigate the Einstellung effect.
How does one avoid the Einstellung effect? There is no sure-fire method but here are some suggestions.
The insidious thing about the Einstellung effect is that it affects both novices and experts. More training will not help you avoid the trap. We can, however, lessen the probability that we will fall into the trap.
So the next time your heart leaps for joy because you finally found a solution to a thorny problem, take a minute to sniff your code. If you get a whiff of herring, you might want to take a fresh look at the code!