One Refactoring Rule Great Developer Should Know

One Refactoring Rule Great Developer Should Know

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.

Wait.

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.

rule-of-three programming coding javascript

What is Geek Coin

What is GeekCash, Geek Token

Best Visual Studio Code Themes of 2021

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Principles of Functional Programming in JavaScript That Will Make Your Coding Life Easier

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.

4 Ways You Can Get Rid of Dirty Side Effects for Cleaner Code in JavaScript

4 Ways You Can Get Rid of Dirty Side Effects for Cleaner Code in JavaScript. Bugs are born in many ways. Creating side effects is one of them. Some people say side effects are evil, some say they’re not.

Who Else Wants to Write Clean JavaScript Code?

Who Else Wants to Write Clean JavaScript Code? 7 Tips to Make Your Coworkers Fall in Love With Your Code.

Code Formatting with Prettier in Visual Studio Code

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.

Top 15 Simple Coding Techniques to Get Your Tasks Done with Shorter Code in JavaScript

Don’t waste time writing long code while you can make it short, yet clearer and easier to read. In this Javascript tutorial, we'll discuss 15 Simple Coding Techniques to Get Your Tasks Done with Shorter Code in JavaScript