Refactoring as Anxiety Relief

There’s a meta code smell I’d like to now dub the Anxiety Rug, the programmer’s parallel of moving the furniture around to avoid existential dread. It goes like this: a long file provokes your sensibilities, so you swipe it under the rug into a tree of files and folders; a shrunken scrollbar portends bad omens and demands a slew of micro helper / manager / servicer classes; a server has the audacity of trying to respond to more than one type of request, and is quickly shoe-horned into its rightful place as a cog in the machine. This is reminiscent of “In Smalltalk, everything happens somewhere else”.

On the flip side, two eerily-similar-but-not-quite-the-same functions are turned into one basket case of conditionals and edge cases; a wrapper is introduced to orchestrate several functions and, little by little, accumulates fat and configuration options in between their seams; A group of services is identified as having some common functionality and authority is rolled over to a common governor which suddenly does too many things.

The cycle continues. On Mondays we say Don’t Repeat Yourself, on Tuesdays Everything Should Do One Thing and One Thing Only. A large part of programming is an inane battle of semantics. There is no free lunch in understanding a new codebase. No Zen in an all-in-one monolith, no bliss in a swarm of microservices. In between, a million different configurations, and no one will agree with you on the right one. Take a month, and you won’t even agree with yourself.

Some things — especially at the edge where software meets the real world and its needs — are inherently complex. Nothing we can do about it. No amount of shuffling and reorganizing and abstracting will make it go away. It is just a fact of the world. Some things are problems, and they can be solved. Others are difficulties, and they can only be recognized, then hopefully alleviated, and permanently endured. Differentiating between accidental and essential complexity is the Serenity Prayer of the programmer. Understanding which is which helps in dealing with the anxiety and saves pointless reorganization exercises.