DRY or WET and Why?

Noopur R K
2 min readAug 27, 2019

--

The principles of Software Development have always interested me. Many practices have learnt from my professional life which I apply to the code that I write for the various projects of my Masters. Today, I stumbled on the technical term for the principle that I quote and try to abide by the most.

https://deviq.com/don-t-repeat-yourself/

DRY — Don’t Repeat Yourself.

According to this principle, a single piece of information should be present in only one place and in an authoritative manner in your system.

To put it in simple terms avoid redundant repeated code. If you are reiterating the same code almost everywhere in your system, that piece of code has to be locked up as a method for good.

The violations of this principle can be grave.

You know that one configuration you keep changing in 100 different files almost always. The one thing that is susceptible to maximum changes and you have lavishly littered it around in your codebase, change that redundancy to mitigate hours of effort put to change it.

How to inculcate this practice in your code?

1. Always think of your code as a series of smaller modules that will work in conjunction with each other.

2. Think of code that will be reusable and try to form utility classes.

3. Divide your logic and lock them in a simple short sequence of code.

4. If you want your code to be written in Object-oriented fashion, think of behaviours that can be classified in classes.

5. Remember less code, less maintainability.

The antagonist to the DRY principle is the WET principle.

Write Every Time or the WET principle is when you don’t follow the DRY principle. I think the more appropriate way of putting this is — Waste Everyone’s Time.

Here, the WET behaviour of the code can be something as simple as a comment notation used everywhere in the code.

Moral: Try to achieve concise code by adapting to the DRY principle.

--

--