# Code Smell 170 - Refactor with Functional Changes

*Developing is great. refactoring is amazing. Don't make it at the same time*

> TL;DR: Don't change functionally and refactor at the same time.

# Problems

- Hard to review solutions

- Merge Conflicts

# Solutions

1. Never change functionality while refactoring

# Context

Sometimes we detect a refactoring is needed for further development.

We are experts at learning.

We should put our solution on hold. Work on the refactoring, and continue with our solution.

# Sample Code

## Wrong

[Gist Url]: # (https://gist.github.com/mcsee/f07e5ef021600a82d086fe7cb001fb84)
```kotlin
getFactorial(n) {
  return n * getFactorial(n);
}

// Rename and Change

factorial(n) {
  return n * factorial(n-1);
}

// This is very small example
// Things go works while dealing with huge code
```

## Right

[Gist Url]: # (https://gist.github.com/mcsee/7ae7ad75035ee5c5d1180d0db966dece)
```kotlin
getFactorial(n) {
  return n * getFactorial(n);
}

// Change

getFactorial(n) {
  return n * getFactorial(n-1);
}

// Run the tests

factorial(n) {
  return n * factorial(n-1);
}

// Rename
```

# Detection

This is a refactoring smell.

[X] Manual

# Tags

- Refactoring

# Conclusion

We should use a physical token.

Either we are in the refactoring stage or the developing stage.

# 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 [Dannie Jing](https://unsplash.com/@dannie_jing) on [Unsplash](https://unsplash.com/s/photos/circus)
  
* * *

> When I’m studying code, refactoring leads me to higher levels of understanding that I would otherwise miss. Those who dismiss comprehension refactoring as useless fiddling with the code don’t realize they never see the opportunities hidden behind the confusion.

_Martin Fowler_
 
%[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]
