First rule of coding: DRY (Don't Repeat Yourself )

The principle and practices of software development have always interested me. In this blog, we are going to talk about the first principle of coding that I ever learned about i.e. Don't Repeat Yourself principle.

The DRY principle is stated as “Every piece of knowledge must have a single, unambiguous, authoritative representation within a system” by Andy Hunt and Dave Thomas in their book The Pragmatic Programmer. In DRY code, we do functioning to codes that are repetitive and perform the same task multiple times in your code. And there should only ever be one copy of any important piece of information.

Let's say you are programming an application that is a blog reading site and there are 100 articles on the site. If you program 100 different view pages for the article, then it will become very high maintenance and expensive process. So, in this case, you need to write a base template in your code and serve the same base template for every article view.

Starting your DRY code:

  1. Change your repetition into the functional module.
  2. Always remember that less code = low maintainence
  3. If your codes are written in object-oriented style then always classify properties in Class module.

P.S. We also have the WET principle:

writes code, mostly backend