# Code Smell 233 - Collections Count

> TL;DR: Chose narrow names

# Problems

- Bad Naming

# Solutions

1. Accurately describe your collections

# Context

Names are significant and should not deceive the reader.

You name things and lose the scope of the name. 

It is important to be accurate of the expected reference on the names.

# Sample Code

## Wrong

[Gist Url]: # (https://gist.github.com/mcsee/75e43eb48e025f1e41e65c1e7439c7b7)
```javascript
const standardModelParticles = {
  quarks: [
    {
      name: "Up",
      charge: "2/3",
      type: "Quark",
    },
    {
      name: "Down",
      charge: "-1/3",
      type: "Quark",
    },
    // ...
  ],
  leptons: [
    {
      name: "Electron",
      charge: "-1",
      type: "Lepton",
    },
    {
      name: "Muon",
      charge: "-1",
      type: "Lepton",
    },
    // ...
  ],
  gaugeBosons: [
    {
      name: "Photon",
      charge: "0",
      type: "Boson",
    },
    {
      name: "W Boson",
      charge: "Â±1",
      type: "Boson",
    },
    // ...
  ],
  higgsBoson: [
    {
      name: "Higgs Boson",
      charge: "0",
      type: "Scalar Boson",
    },
  ],
};
 
const quarks = standardModelParticles.quarks.length; 
// Bad name. It does not represent a count
```

## Right

[Gist Url]: # (https://gist.github.com/mcsee/8b0d7ed980f656ff26f070e228fbc760)
```javascript
const standardModelParticles = {
}; // Same as the "Wrong" Example
 
const quarksCount = standardModelParticles.quarks.length; 
```

# Detection

[X] SemiAutomatic 

Some linters can check the types and names and infer a mistake

# Tags

- Namings

# Conclusion

Take care of your names.

Use automatic refactor tools whenever you come across a bad name.

# Relations

%[https://maximilianocontieri.com/code-smell-163-collection-in-name]

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

%[https://maximilianocontieri.com/code-smell-33-abbreviations]

# Disclaimer

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

# Credits

Photo by [Sandy Millar](https://unsplash.com/@sandym10) on [Unsplash](https://unsplash.com/photos/a-group-of-three-nesting-dolls-sitting-on-top-of-a-wooden-table-5PCeHBkMCmk)
    
* * *

> Some people are good programmers because they can handle many more details than most people. But there are a lot of disadvantages in selecting programmers for that reason — it can result in programs that no one else can maintain.

_Butler Lampson_
 
%[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]
