One Refactoring Rule Great Developer Should Know. You are a good developer, and see it is a duplication of code. With DRY in mind, you refactor. Learn the rule and become better at refactoring. A good programmer will not be lulled into complacency.
Learn the rule and become better at refactoring
Let’s say you wrote exact same code twice. You are a good developer, and see it is a duplication of code. With DRY in mind, you refactor.
But is that the correct way? Did you make the code more maintainable? What’s the metric in this scenario?
Let’s get into the details.
This is the rule. Wait. Wait for more duplication.
Also known as the “Rule of Three”. Or “Write Everything Twice”.
You see the same code often, three or more times?. Refactor. Make abstractions. If not leave it as is.
“Three strikes and you refactor” — Nicolas Carlo
Accept small duplication. It’s not that bad. The wrong abstraction is even worse than duplication.
When reusing code, copy it once, and only abstract the third time. — The Rule of Three
The cost of not waiting is a bad abstraction. You don’ have enough generics to extract. Two use cases are not enough. You need more than two, then you can make abstractions.
Who else loves to write side-effects-free functions? I think we, as programmers, all do. Today, in this story, I will walk you through the basic principles of functional programming that will make your coding life easier.
Formatting code consistently is a pain, especially when working on a team. The beauty of modern-day web development is that the tooling has gotten so much better! In this article, we will look at setting up Prettier to automatically format your code in Visual Studio Code.