“Bad abstraction is worse than duplication”
Oh shit, thank you so much for this part ! I don’t even count number of time I had to face enthusiasts developers saying "These lines of code are very similar, let’s factorize them ! "
And that’s how MathManagerHelper class is born…
God yeah - this hits hard with me. I work in a place where the DRY principle is chanted like a mantra and I have to push back against it constantly. It’s like the one principle jr. devs learn (along with “never hardcode anything”) that just gets applied to everything whether it makes sense or not.
"These lines of code are very similar, let’s factorize them ! "
“We should take three simple functions that run similar (but different) things and make them call a single large complicated function that takes a parameter that tells it how to execute!”
::shudder::
My rule of three: consider rewriting any article, blog, exhortation, argument, leaflet, or wiki page that uses more than three fonts, sizes, colors, or styles.
- Don’t use LLMs
I would say: Learn to use LLMs as a tool rather than a crutch.
+++ I cannot stress this enough.
Programmers tend to get over obsessive about DRY code because it seems like it should be easier to maintain fewer functions and writing less code should be easier right? But it tends to ignore the actual subtle differences between the different consumers of that abstraction, and that leads to massively branching functions that couple unrelated parts of the codebase together. These then become impossible to read and change without worrying about breaking something else.
When I was at Thoughtworks (Martin Fowler’s current company), we were also taught the rule of three for refactoring, and were taught to always optimize your code for readability and maintainability first and foremost. Refactoring and improving easy to read code is always relatively trivial, by nature of it being clear, concise and easy to read, and that can be done once you have a reason to do so (i.e. performance issue etc), so there’s no point over optimizing for anything else up front.
This talk from Dan Abramov (one of the lead devs of React) does a really really good job explaining some of these issues and is entirely worth the full watch/listen (do it on company time, it’s professional development):
https://www.deconstructconf.com/2019/dan-abramov-the-wet-codebasets