Don’t Repeat Yourself

Leave a comment

Don’t Repeat Yourself (DRY) is a software development principle that prevents waste through the repetition of code. When code is designed and developed, it should be abstract. As a result of abstraction, the code is easier to maintain and extend. Smarter code leads to less code waste, which leads to better software. Imagine if you find a bug in one part of your code, and the bug is repeated in many different places because the code was not implemented with the DRY principle. In this case, you would need to change the code in many different places to fix the bug.

However, the implementation of the principle is based on the situation. There are times when violating the DRY principle makes sense. These situations may include:

  • Performance. In some cases, abstraction may actually slow down your code
  • Understanding the code. You may have complex business logic that is easier to implement without abstracting the code. In this case, you may save time and effort maintaining the code going forward if you violate DRY
  • Ability to change the code later. You may not need the code¬†abstracted in the future

The failure to implement DRY is often referred to as WET.

Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

Leave a Reply

Your email address will not be published. Required fields are marked *

1 × five =