# Code Smell 163 - Collection in Name

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

# Problems

- Readability

- Abstraction Abuse 

- [Bad Naming](https://maximilianocontieri.com/what-exactly-is-a-name-part-ii-rehab)

# 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](https://maximilianocontieri.com/null-the-billion-dollar-mistake) and [IFs](https://maximilianocontieri.com/how-to-get-rid-of-annoying-ifs-forever).

We often use bad and vague names instead of looking for good names in the [MAPPER](https://maximilianocontieri.com/what-is-wrong-with-software).

# Sample Code

## Wrong

[Gist Url]: # (https://gist.github.com/mcsee/685b6d202e94d8c5b410dafd15d8b5de)
```javascript
foreach (var customer in customerCollection)
{
    // iterate with current customer
}

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

## Right

[Gist Url]: # (https://gist.github.com/mcsee/a8a2b41722dde835757f360a5d1f01d2)
```javascript
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

%[https://maximilianocontieri.com/code-smell-134-specialized-business-collections]

# More Info

%[https://maximilianocontieri.com/what-exactly-is-a-name-part-ii-rehab]

# Disclaimer

Code Smells are just my [opinion](https://maximilianocontieri.com/i-wrote-more-than-90-articles-on-2021-here-is-what-i-learned).

# Credits

Photo by [Mick Haupt](https://unsplash.com/@rocinante_11) on [Unsplash](https://unsplash.com/s/photos/collector)
  
* * *

> 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_
 
%[https://maximilianocontieri.com/software-engineering-great-quotes]

* * *

This article is part of the CodeSmell Series.

%[https://maximilianocontieri.com/how-to-find-the-stinky-parts-of-your-code]
