DEV Community

Cover image for Code Smell 170 - Refactor with Functional Changes
Maxi Contieri
Maxi Contieri

Posted on • Originally published at maximilianocontieri.com

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

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