Skip to main content

Command Palette

Search for a command to run...

Code Smell 163 - Collection in Name

Have you ever seen a CustomerCollection?

Published
2 min read
Code Smell 163 - Collection in Name
M

I’m a senior software engineer loving clean code, and declarative designs. S.O.L.I.D. and agile methodologies fan.

TL;DR: Don't use 'collection' in your name. It is too abstract for concrete concepts.

Problems

Solutions

  1. Rename the collection with a specific name.

Context

Naming is very important.

We need to deal a lot with collections.

Collections are amazing since they don't need nulls to model the absence.

An empty collection is polymorphic with a full collection.

We avoid nulls and IFs.

We often use bad and vague names instead of looking for good names in the MAPPER.

Sample Code

Wrong

foreach (var customer in customerCollection)
{
    // iterate with current customer
}

foreach (var customer in customersCollection)
{
    // iterate with current customer
}

Right

foreach (var customer in customers)
{
    // iterate with current customer
}

Detection

[X] Semi-Automatic

All linters can detect a bad naming like this.

It can also lead to false positives so we must be cautious.

Tags

  • Naming

Conclusion

We need to care for all our clean code, variables, classes, and functions.

Accurate names are essential to understand our code.

Relations

More Info

Disclaimer

Code Smells are just my opinion.

Credits

Photo by Mick Haupt on Unsplash


Alzheimer's Law of Programming: Looking at code you wrote more than two weeks ago is like looking at code you are seeing for the first time.

Dan Hurvitz


This article is part of the CodeSmell Series.

F

I'm a tech editor, and I did a review of this article over on my blogstar series. Nice work establishing context with your writing!

https://flicstar.hashnode.dev/blogstar-maxi

2

Code Smells

Part 1 of 50

In this series, we will see several symptoms and situations that make us doubt the quality of our developments. We will present possible solutions. Most are just clues. They are no hard rules.