DEV Community

Cover image for Confessions: How I Got Addicted to Clean Code Principle - DRY
Ravina Deogadkar
Ravina Deogadkar

Posted on

Confessions: How I Got Addicted to Clean Code Principle - DRY

Hello folks, hope you are doing well! This is my first blog after a long break😞 Hope you have read my previous blogs. This is my first blog in clean code series, I will be posting everything about clean code practice and code smells.
i

Don't Repeat Yourself

DRY stands for Don't Repeat Yourself is a basic software development principles implying reducing code repetition. As it states "Every small piece of code or logic should be single or unambiguous within system".

Guidelines

When you need to use similar logic at different location, it's definitely a sign of wet code. If in future the requirement changes and you need to modify the logic. Obviously logic needs to be modified at multiple locations and lots of test cases needs to be updated and might be new test cases needs to be created .......
Another hill to climb though!
So determine the identical patterns in code and extract them into common functionality and reference this common logic. Any future changes in code can be easily incorporated with less changes, Makes code easily maintainable.

Advantage

  • Less code: Less code implies less code to maintain and less code to be tested. Number of test cases will be reduced with less code.

  • Readability: Functions will be refactored to include only necessary code and common code will be extracted to utils function. Code won't be repeated at many places and will be more easily readable to other developers.

  • Maintainence: Code becomes more maintainable since single code updation place. Future updation in code can be easily incorporated with less changes.

Happy coding!..

Top comments (0)