The principles war:🏜️DRY vs💋KISS and an unexpected hero😎
The most common advice given to developers is Don't Repeat Yourself, the well-known DRY.
Followed by the sly tip Keep It Simple, Stupid; sweetened by the KISS acronym.
But, are they compatibles? Let's see 🧵👇
🏜️ Being DRY in programming is very good advice for a good reason:
When something changes, you only have to take care of the unique place where this feature is written.🦄
So is it not about code duplication or code reuse?
No, those are good consequences.
🤢 But, code duplication is a smell of code, isn't it?
Yes, and you should be concerned about any duplicates in your codebase.
Although don't rush to fix it.
Why?
Because chances are that you arrive with a wrong abstraction that it's worst than the initial duplication.
🍰 What could be wrong with an abstraction?
Software, even computers, is all about layers of abstraction!
Yes, but they come with a cost and need to be understood like a tradeoff. ⚖️
- 🏋️ Any indirection layer weighs as a complexity pound
- 🔐 Any reusable component might be caught by its dependents in a coupling trap
And these go totally against the sweet KISS principle.
🕺 Now I am caught in a trap, I can't walk out... says suspicious minds.
Not for long. You only have to take patience, breath, and count up to three.🧘
Most of the time the wrong abstraction comes from a very pernicious vice: Premature Optimization. 🤓
To rescue us there is another hero principle, enter YAGNI: You aren't gonna need it 😎
🧘 Basically, it tells you to wait for the problems before solving them.
It is a matter of time that duplication turns into triplication, but by then, you will have more knowledge and more reasons to pay for the abstraction.
So in summary:
- 🏜️ DRY is good advice but it comes at a cost.
- ⚖️ Load up on reasons and knowledge before creating abstractions.
- 🧸 Keeping your code simple is the ultimate demonstration of your talent.
- 💋 KISS a lot.
🏷️ Naming is so important and so cumbersome in programming as Phil Karlton coined in his famous cite:
"There are only two hard things in Computer Science: cache invalidation and naming things."
A thread 🧵👇
📐From the design phase.
Having a common name glossary is the central point in methodologies like #DDD.
But even if you don´t follow it, you will appreciate having a #ubiquitous language to communicate with all the people involved.
🚧 In the architect's hands naming is the core of its work.
Creating #patterns is given a name to proven solutions. Using them is using those names.
Dividing codebases and defining #layers and #tiers forces you to give them a name.
🏷️ Naming is so important and so cumbersome in programming as Phil Carlton coined in his famous cite:
"There are only two hard things in Computer Science: cache invalidation and naming things."
📐From the design phase.
Having a common name glossary is the central point in methodologies like #DDD.
But even if you don´t follow it, you will appreciate having a ubiquitous language to communicate with all the people involved.
🚧 In the architect's hands naming is the core of its work.
Using #patterns is given name to proven solutions.
Defining #layers and tiers forces you to give them a name.