Sitemap
Geek Culture

A new tech publication by Start it up (https://medium.com/swlh).

Member-only story

Does Your Code Smell?

Trey Wilson
Geek Culture
Published in
4 min readOct 5, 2021

--

Photo by Clay Banks on Unsplash

A code smell is a surface indication that usually corresponds to a deeper problem in the system.

- Martin Fowler

While this eventually can happen if a code smell is left in production, it doesn’t always mean there is a deeper problem yet. The accumulation of multiple code smells is what generally causes the deeper problem in the system.

In this article I want to go over the most common code smells I see while reviewing my own code along with my peers. Developing a sense for code smell will help keep you and your peers’ code smelling fresh.

Long Functions

This is one of the most common code smells. To help know when a function is too long, some will try and say when a function is ‘x’ lines long, it should be split out into a new function. While there is value to this, I think it is too arbitrary to pick a line limit. However, it can be a rule of thumb to start with. Each language will generally have their own suggested line limit. My recommendation, don’t use line limits as the only rule of thumb, similarly to how you shouldn’t use test coverage percentage as the only rule of thumb for quality of unit test.

Questions I ask to myself when wondering if a function is too long:

Is this function handling multiple conditions?

--

--

Trey Wilson
Trey Wilson

Written by Trey Wilson

Principal Staff Software Engineer that enjoys all things software related

No responses yet