Asier's thoughts

Blogging about software development

DRY – Don’t Repeat Yourself

2 Comments

The first principle of the red grade is Don’t Repeat Yourself or DRY. It’s origin can be found in the Pragmatic Programmer, one of the most important books in the programming world.

220px-The_pragmatic_programmer

DRY tackles code repetition and states that we should avoid it.

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

Quite simple and obvious thing. However, not everybody follows this. The copy and paste is much easier than having to think how to avoid this duplication.

Much easier? well, at the moment.. But what about when you came back to that piece of code and whant to change something? You will have to make sure that you are making the change in every duplicated piece.. if the duplication has happened in more than a place this could became a maintenance nightmare. Also, this duplication it is just clutter in the code which makes in more difficult to read. And we spend most of time reading code.

So, if you want to write maintainable clean code DO NOT REPEAT YOURSELF!

Advertisements

2 thoughts on “DRY – Don’t Repeat Yourself

  1. Pingback: Clean Code Development: Read Grade « Asier's thoughts

  2. Pingback: Favour composition over inheritance « Asier's thoughts

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s