How to recognize and avoid duplicate code

Published: Nov 16, 2022

Have you ever heard an engineer say "don’t repeat yourself” (DRY).  This piece of sage engineering advice is often overlooked or ignored. Why -  You might ask?  Let's take a look.

Unnecessary Duplication

The software engineer who was able to recognize and mitigate duplicate code can produce a cleaner implementation in a faster amount of time. By contrast, the software engineer who duplicates code over and over simply creates a mess that is very difficult to debug and leaves legacy problems for others to deal with.

Every single line of code that goes into your project needs to be maintained in some form or fashion. Unnecessary duplication of code ends up bloating the overall CodeBase. This bloat has several negative side effects on your project code. First is that the bloated code makes it very difficult for others on the team to understand the code’s purpose and intentions.  Second is that the bloated code creates more opportunities for accidental complexity and hard-to-find bugs. in short, duplicating code wastes your time and efforts.

Missing Abstraction

Duplicate code is often created when functions and routines are not properly abstracted to accomplish a specific goal or task. In other words, if a function is very long and monolithic in its design, it has greater odds of containing duplicate code that other routines are functions will need as well.

If we do a better job of abstracting out the pieces of code that can be reused across the application we can create very specific routines that accomplish necessary goals. These abstracted functions can be called upon when needed reducing the need for duplicating code.

Junior and Senior Engineers

Creating duplicate code is a plague that can be found among junior as well as senior engineers.   Junior engineers often struggle with duplicate code simply because they lack experience in building larger scale applications. Senior engineers struggle with duplicate code simply because of laziness. They mistakenly think that it is faster to write a specific function to accomplish their task than it is to properly abstract the various components needed to complete that task.

 

The end goal of the don’t repeat yourself programming principle is to create simpler more maintainable and higher quality applications.

Enjoyed this? Join the community...
Please login to submit comments.


 
Copyright © 2024 Design The Game by Dimbal Software. All Rights Reserved.
Dashboard | Privacy Policy | Terms of Service