main banner

Development

Duplicate Code and how Visual Studio can help you

In any cases, duplicate code should be avoided, because code reuse, encapsulation and maintainability are not accomplished. If encapsulation/code reuse is made properly, then we know for sure that we won't revisit that working code (unless we need to extend it). Writing good code and following best practices avoid technical debt.

Duplicate code is inserted into a project typically by:

  • Copying and pasting a section of the code that already works and is similar to this new piece.
  • Functionality implemented independently which in the end, results very similar to code in another place of the project.

In any cases, duplicate code should be avoided, because code reuse, encapsulation and maintainability are not accomplished. If encapsulation/code reuse is made properly, then we know for sure that we won't revisit that working code (unless we need to extend it). Writing good code and following best practices avoid technical debt.

Visual Studio's Code Clone Detection, available from version 2012, can find duplicate or highly similar code in C# and Visual Basic. The article Finding Duplicate Code by using Code Clone Detection clearly explains how to use this feature.


Osvaldo G.

Calling Osvaldo “el Doc” is no coincidence, he is part of the Inflection Point’s gurus and has been working in the company for 9 years; his degree in Computer Engineering, the numerous certifications and more than 15 years of experience in Microsoft technologies, have made of him a mentor for many and also an avid writer for Inflection Point’s blog with tips and facts that have saved more than one coder in their quest for better coding. He comes from San Nicolás de los Garza, Nuevo Leon and is a Tigres (local soccer team) fan.

Articles