DEV Community

Cover image for Top 10 code smells every engineer should know to improve their pull requests
Arthur Coudouy
Arthur Coudouy

Posted on

10 1 1 1 1

Top 10 code smells every engineer should know to improve their pull requests

How to avoid difficult code reviews? Identify code smells!

According to Wikipedia:

In computer programming, a code smell is any characteristic in the source code of a program that possibly indicates a deeper problem.

After a few years of helping developers review code, I came up with 10 code smells and how to fix them while building my project Axolo.

๐Ÿง Refactoring Large or Complex Methods

Navigating through methods that sprawl across numerous lines or twist into complexity can be daunting. Simplification is key!

The fix? Employ a linter to enforce a maximum number of lines. Deconstruct these behemoths into smaller, more focused methods, each dedicated to a singular task.

๐Ÿค” Addressing Long Parameter Lists

A lot of parameters can muddle method signatures, making them prone to mistakes.

The fix? Consolidate related parameters into a single object. Adopt the "parameter object" pattern to streamline your functions, enhancing their readability and maintainability.

๐Ÿ™„ Minimizing Excessive Comments

An overload of comments often signals that the code isn't speaking for itself as clearly as it should.

The fix? Strive for code that explains itself through judicious naming and structure. Reduce reliance on comments, allowing the code's purpose and function to be immediately apparent.

๐Ÿคฆ Eliminating Duplicate Code

Repetitive code fragments are not just a nuisance; they complicate updates and can introduce inconsistencies.

The fix? Seek out and consolidate repetitive code segments into common functions. Adhering to the DRY (Don't Repeat Yourself) principle simplifies future maintenance and modifications.

๐Ÿ˜• Harmonizing Inconsistent Naming Conventions

Naming chaos confounds understanding and introduces potential errors.

The fix? Commit to a unified naming convention. Names that are clear and consistent pave the way for code that's more approachable and decipherable.

๐Ÿ˜ฌ Enhancing Error Handling

Neglecting comprehensive error management can lead to erratic behavior and a codebase that's tough to sustain.

The fix? Embrace thorough error management. Logically log and manage exceptions to bolster the code's stability and dependability.

๐Ÿคฏ Simplifying Overused If/Else Constructs

An abundance of if/else branches can tangle code, making it challenging to read and adjust.

The fix? Lean on data structures or design patterns, such as polymorphism, to untangle complex logic, thereby enhancing the code's legibility and adaptability.

๐Ÿ‘Ž Refining Inheritance Usage

Inappropriate reliance on inheritance can entangle code further, reducing its adaptability.

The fix? Verify that inheritance is used judiciously. Opt for composition over inheritance to achieve a code structure that's more flexible and straightforward to maintain.

Be honest, which one do you usually see in your PR? If you think I'm missing something, let me know in the comments!

Top comments (1)

Collapse
 
juliomoreyra profile image
JulioMoreyra โ€ข

Great tips! Thanks

๐Ÿ‘‹ Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay