# Dispensables

> Smells where code, comments or abstractions add nothing, and removing them makes the program shorter and clearer with no loss of behavior.

- kind: category
- category: refactoring
- canonical: https://aipatterns.dev/refactoring/smells/dispensables
- inspired-by: https://refactoring.guru/refactoring/smells/dispensables

## What these smells share

Dispensables are things you can delete. Some were useful once and outlived their purpose. Some were built for a future that never arrived. Some copy logic that already exists elsewhere. All of them cost reading time and maintenance while giving nothing back.

The default treatment is removal or merging. That makes these the safest smells to fix, provided you confirm the code is truly unused or truly duplicated.

## Members

- [Comments](https://aipatterns.dev/refactoring/smells/comments.md): comments that explain what unclear code does, instead of the code being made clear.
- [Duplicate Code](https://aipatterns.dev/refactoring/smells/duplicate-code.md): the same logic appears in two or more places and must be changed in each.
- [Lazy Class](https://aipatterns.dev/refactoring/smells/lazy-class.md): a class does too little to justify its existence.
- [Data Class](https://aipatterns.dev/refactoring/smells/data-class.md): a class has fields and accessors but no behavior, while others operate on its data.
- [Dead Code](https://aipatterns.dev/refactoring/smells/dead-code.md): variables, parameters, methods or branches that are never used or never reached.
- [Speculative Generality](https://aipatterns.dev/refactoring/smells/speculative-generality.md): hooks, parameters and abstract classes added for needs that do not exist.

## How to choose within this category

- If the code is never executed, it is [Dead Code](https://aipatterns.dev/refactoring/smells/dead-code.md). Delete it.
- If the code runs but copies other code, it is [Duplicate Code](https://aipatterns.dev/refactoring/smells/duplicate-code.md). Merge it.
- If an abstraction exists with one implementation and no planned second, it is [Speculative Generality](https://aipatterns.dev/refactoring/smells/speculative-generality.md). Collapse it.
- If a class exists but does almost nothing, it is [Lazy Class](https://aipatterns.dev/refactoring/smells/lazy-class.md). Inline it into its user.
- If a class holds data and others do the work on it, it is [Data Class](https://aipatterns.dev/refactoring/smells/data-class.md). Move the behavior in, rather than deleting the class.
- If a comment explains what a block does, it signals [Comments](https://aipatterns.dev/refactoring/smells/comments.md). Extract and name the block, then delete the comment. Keep comments that explain why.

## Typical treatments

- [Extract Method](https://aipatterns.dev/refactoring/techniques/extract-method.md), [Pull Up Method](https://aipatterns.dev/refactoring/techniques/pull-up-method.md) and [Form Template Method](https://aipatterns.dev/refactoring/techniques/form-template-method.md) for duplication.
- [Inline Class](https://aipatterns.dev/refactoring/techniques/inline-class.md) and [Collapse Hierarchy](https://aipatterns.dev/refactoring/techniques/collapse-hierarchy.md) for lazy classes and speculative abstractions.
- [Remove Parameter](https://aipatterns.dev/refactoring/techniques/remove-parameter.md) for unused arguments.
- [Move Method](https://aipatterns.dev/refactoring/techniques/move-method.md) and [Encapsulate Field](https://aipatterns.dev/refactoring/techniques/encapsulate-field.md) for data classes.

## For agents

- Verify "unused" with a whole-repository search, including reflection, string-based lookups, public API exports and configuration files. Static analysis misses dynamic calls.
- Do not merge code that only looks alike. Two blocks that change for different reasons are not duplicates.
- A data class at a system boundary (DTO, wire format, database row) is often intentional.
