# Code Smell 169 - Glued Methods

> TL;DR: Try to be as atomic as possible in your methods

# Problems

- Coupled Code

- Harder to test

- Harder to read

# Solutions

1. Break the method

# Refactorings

%[https://maximilianocontieri.com/refactoring-002-extract-method]

# Context

If you name a method with 'And' you are probably missing an extract-and-break method opportunity.

# Sample Code

## Wrong

[Gist Url]: # (https://gist.github.com/mcsee/a5f7f776b32957ad3d40d57b4ff99c7f)
```rust
calculatePrimeFactorsRemoveDuplicatesAndPrintThem()

// Three responsibilities
```

## Right

[Gist Url]: # (https://gist.github.com/mcsee/435d364b6ae0222952ace057ec099e94)
```rust
calculatePrimeFactors();

removeDuplicates();

printNumbers();

// Three diferent methods
// We can test them and reuse them
```

# Detection

[X] Semi-Automatic 

Some linters can warn us about methods including the term 'and'.

# Tags

- Coupling

# Conclusion

When making methods, it is very important to play some rubber duck story and tell ourselves if we are making things right.

# Relations

%[https://maximilianocontieri.com/code-smell-85-and-functions]

# 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 [Scott Sanker](https://unsplash.com/@scottsanker) on [Unsplash](https://unsplash.com/s/photos/glue)  

* * *

> Learning the art of programming, like most other disciplines, consists of first learning the rules and then learning when to break them.

Joshua Bloch
 
%[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]
