# Code Smell 257 - Name With Collections

> TL;DR: Drop "collection" prefix for clarity.

# Problems

- Redundant Naming

- Verbose Code

- Reduced Readability

- Refactoring Challenges

- Coupled to implementation

# Solutions

1. Use Simple Names

2. Remove 'collection' [from the name](https://maximilianocontieri.com/what-exactly-is-a-name-part-ii-rehab)

3. Use plural names without the word 'collection'

# Context

When you prefix properties with terms like "collection," you introduce redundancy and verbosity into your code. 

This makes your code harder to read and maintain and adds unnecessary complexity. 

Coupling the name to a collection implementation prevents you from introducing a proxy or middle object to manage the relation.

# Sample Code

## Wrong

[Gist Url]: # (https://gist.github.com/mcsee/b929bfe2ee406a7d9a822c5318db5b61)

```rust
struct Task {
    collection_of_subtasks: Vec<Subtask>,
    subtasks_collection: Vec<Subtask>,
}

impl Task {
    fn add_subtask(&mut self, subtask: Subtask) {
        self.collection_of_subtasks.push(subtask);
        self.subtasks_collection.push(subtask);
    }
}
```

## Right

[Gist Url]: # (https://gist.github.com/mcsee/1c4c774f018e5f6cde339148962a4562)

```rust
struct Task {
    subtasks: Vec<Subtask>,
}

impl Task {
    fn add_subtask(&mut self, subtask: Subtask) {
        self.subtasks.push(subtask);
    }
}
```

# Detection

[X] Automatic 

You can add rules to your linter preventing these redundant names.

# Tags

- Naming

# Level

[X] Beginner

# AI Generation

AI code generators produce this smell if they try to over-describe property names. 

They tend to generate overly verbose names to be explicit, which can lead to redundancy.

# AI Detection

AI tools can fix this smell if you instruct them to simplify property names. They can refactor your code to use more concise and clear names.

# Conclusion

Simplifying property names by removing prefixes like "collection" leads to more readable and maintainable code.

It would be best to focus on clear, direct names that communicate the purpose without redundancy.

# Relations

%[https://maximilianocontieri.com/code-smell-38-abstract-names]

%[https://maximilianocontieri.com/code-smell-171-plural-classes]

%[https://maximilianocontieri.com/code-smell-113-data-naming]

# More Info

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

# 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 [Karen Vardazaryan](https://unsplash.com/@bright) on [Unsplash](https://unsplash.com/photos/die-cast-car-collection-on-rack-JBrfoV-BZts)
   
* * *

> Good design adds value faster than it adds cost.

_Thomas C. Gale_
 
%[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]
