DEV Community

Cover image for Code Smell 153 - Too Long Names
Maxi Contieri
Maxi Contieri

Posted on • Originally published at maximilianocontieri.com

Code Smell 153 - Too Long Names

Names should be long and descriptive. How Long?

TL;DR: Names should be long enough. No longer.

Problems

  • Readability

  • Cognitive Load

Solutions

  1. Use names related to the MAPPER

Context

We used very short names during the 50s and 60s due to space and time constraints.

This is no longer the case in modern languages.

Sometimes we get too excited.

Naming is an art and we should be cautious with it.

Sample Code

Wrong

PlanetarySystem.PlanetarySystemCentralStarCatalogEntry

// Redundant
Enter fullscreen mode Exit fullscreen mode

Right

PlanetarySystem.CentralStarCatalogEntry
Enter fullscreen mode Exit fullscreen mode

Detection

[X] Semi-Automatic

Our linters can warn us with too long names.

Tags

  • Bloaters

  • Naming

Conclusion

There are no hard rules on name length.

Just Heuristics.

Relations

More Info

Credits

Photo by Emre Karataş on Unsplash


Many people tend to look at programming styles and languages like religions: if you belong to one, you cannot belong to others. But this analogy is another fallacy.

Niklaus Wirth


This article is part of the CodeSmell Series.

Top comments (0)