DRY Programming Practices

Having a clean codebase is a good practice to get into. It makes your code easier to read as well as run more smoothly. One way to have a cleaner codebase is to use the DRY (Don’t Repeat Yourself) programming principle. It is aimed at reducing repetition of information of all kinds, and is especially useful in multi-tier architectures. If you don’t use these principles, think of your work as WET. It Wastes Everyone’s Time when you Write Everything Twice.

There are several ways to keep your code DRY.

Abstraction

The goal of abstraction is to abstract bits of code into a reusable section so that it is not duplicated everywhere. It involves using key concepts like inheritance (making a base class /module that has common logic for others to use) or writing util classes.

 

Rule of Three

If you have identical code in 3 or more places, it should be abstracted into a common method, class, etc. to be reusable and easily maintainable.

 

KISS (Keep it simple stupid!)

There are a few ways to keep your code simple. Don’t cram too much into one little method or function. Plan out your user flow so that you can anticipate interactions. “Clean design leads to clean code.” Beware of “code smell.” 

 

Separation of Concern/ Single Responsibility

Keep your code organized. Separate code into distinct sections so that you can easily go back and find sections for reuse. Have loosely coupled layers. Separate UI from the data layer and the app layer from the integration layer. This will make refactoring simpler. Obfuscate as much as possible to make it easy for partners and other developers to make changes to only the pertinent parts.

 

Single Source of Truth (SSOT)/Single Point of Truth (SPOT)

These are ways of architecting models and data so that every data element is stored exactly once. They use relational schemas instead of duplication.

 

You Aren’t Going to Need It (YAGNI)

Keep your code clean and readable. Remove commented out code and dead or unused code. It is just clutter at that point. It shouldn’t be scary if you are using source control. (If you aren’t, you really should be). This also cuts down on package bloat, making your application smaller.

 

Try DRY Programming

There is no excuse to not use DRY programming principles while building your project. They make your application faster and your code more readable. If you ever need to hand your code off to another developer, they will thank you. Try out this best practice and see how organization and code reuse simplifies your work and gives you more time!

 

Download the PowerPoint

Keep_it_Dry.jpeg
 

SEE OUR JOB OPENINGS