# Code Smell 239 - Big Pull Request

> TL;DR: Always stick to baby steps

# Problems

- Readability

- Code Review time and complexity

- Merge Conflicts

- Testing Challenges

# Solutions

1. Break the change in atomic parts

# Context

When pull requests become very large, they can pose several challenges and problems for development teams.

You must avoid merge requests making different unrelated changes.

# Sample Code

## Wrong

[Gist Url]: # (https://gist.github.com/mcsee/8324fa9cdd7a18f1f66f33ad874244c8)
```javascript
function generateFibonacci(ordinal) {
  const fibonacciSequence = [0, 1];

  for (let index = index; index < ordinal; index++) {
    const nextFibonacci = fibonacciSequence[index - 1]
          + fibonacciSequence[index - 2];
    fibonacciSequence.push(nextFibonacci);
  }

  return fibonacciSequence;
}

// This function solves a very different problem
// You should not mix them in a single pull request

function voyagerDistanceFromEarth(currentDistanceInKms, yearsTravelled) {
  const speedOfVoyagerInKmS = 17; 

  return currentDistanceInKms + 
        speedOfVoyagerInKmS * yearsTravelled * 60 * 60 * 24 * 365.25;
}
```

## Right

[Gist Url]: # (https://gist.github.com/mcsee/9d8adddf01f4ba19917b6307cdcd66f3)
```javascript
function generateFibonacci(ordinal) {
  const fibonacciSequence = [0, 1];

  for (let index = index; index < ordinal; index++) {
    const nextFibonacci = fibonacciSequence[index - 1]
          + fibonacciSequence[index - 2];
    fibonacciSequence.push(nextFibonacci);
  }

  return fibonacciSequence;
}

// You break it into two different pull requests
```

# Detection

[X] Automatic 

You can put a threshold and a warning on big merge requests.

# Exceptions

- Big refactors that cannot be made with baby steps

# Tags

- Complexity

# Level

[ X] Beginner

# AI Assistants

AI assistants do not create pull requests. 

They generate the code you need.

# Conclusion

Software engineers must be experts at managing (and avoiding) [accidental complexity](https://maximilianocontieri.com/no-silver-bullet).

# Relations

%[https://maximilianocontieri.com/code-smell-170-refactor-with-functional-changes]

# 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 [Håkon Grimstad](https://unsplash.com/@grimstad) on [Unsplash](https://unsplash.com/photos/blue-and-black-butterfly-on-brown-stick-hteXWSF9jA4)
    
* * *

> First make the change easy (warning: this might be hard), then make the easy change.

_Kent Beck_
 
%[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]
