This content originally appeared on Go Make Things and was authored by Go Make Things
I often run into two very different types of coders in my travels as a front end consultant.
- Over-abstracted. Everything that could possibly be reused or repeated at some point in the future is pulled out into its own small, single-purpose JS function or CSS class… whether it’s used more than once or not.
- Unabstracted. Everything that’s used more than once is copy-paste-edited, resulting in a lot of duplicate code.
In my experience, both create problems.
An over-abstracted code base is often harder to read, reason about, update, and maintain. Everything is broken up into needlessly tiny, scattered chunks. Figuring out what code does can involve opening a dozen files and toggling back and forth between multiple tabs in your text editor.
An unabstracted code base is usually a tangled mess of spaghetti code. Fixing a bug on one page fixes that bug on exactly one page. You need to manually update that same issue everywhere it’s been copy/pasted. You often miss something, but don’t know about it until someone reports the bug you thought you already fixed.
The happy path is to avoid abstractions entirely when you’re first writing your code.
Get something working. Make it one giant function if you need to, or break it up into a few smaller ones. But do not look for ways to abstract or refine.
When you need to use that code elsewhere (as an HTML component, a CSS feature, or some JS-based interactivity), but a little different, then start looking at which specific pieces of the code need to get abstracted a bit to support that.
Even then, do not engineer the perfect future-proof system.
Abstract just enough to meet the needs of right now, not some imagined future state. Those future needs may never arrive, or they may look very different than you’ve imagined. Abstracting too much, too early, just makes the code harder to work with.
If you’re struggling with this in your code base, get in touch.
My specialty is helping teams identify and fix issues in their code base so that they can work faster and more easily. I’d love to work with you!
Like this? A Lean Web Club membership is the best way to support my work and help me create more free content.
This content originally appeared on Go Make Things and was authored by Go Make Things