Member-only story

Top 10 C# Code Smells

Enhance your coding prowess and steer clear of pitfalls.

Alex Maher
6 min readAug 15, 2023

Amid the lines of logic and layers of algorithms, there lurk imperfections known as “code smells”. This guide dissects these subtle offenders, guiding you towards coding finesse.

I wish these code smell insights had been part of my early learning. Recognizing and addressing these would have undoubtedly streamlined my projects and accelerated my growth as a developer.

1. Duplicated Code

Duplicated code is the déjà vu of the coding world. Repetitive, redundant, and representing a major drain on maintainability, it can erode the foundation of an otherwise sturdy codebase. Just as an artist wouldn’t paint the same stroke twice, a coder shouldn’t reproduce identical lines without good reason.

Example:

// In Login Module
if(password.Length < 8) {
// Error
}

// In Registration Module
if(password.Length < 8) {
// Error
}

Recognize that eerie feeling of repetition? That’s duplicated code whispering!
Recommendation: Swear by the DRY (Don’t Repeat Yourself) principle. Extract and encapsulate duplicated segments. Aim for a sleek and streamlined codebase.

2. Long Method

--

--

Alex Maher
Alex Maher

Written by Alex Maher

.NET C# dev with 10+ yrs exp, self-taught & passionate web developer. Sharing tips & experiences in C# and web dev.

Responses (4)