While there is no golden size of a PR, but usually, a PR should be one self-contained change and it means that:
I generally like to keep my PRs under 250 lines of code. Your team can determine a reasonable number that works best for you.
Some cases when creating big PRs is unavoidable and ok:
I’d like to share my approach to creating smaller pull requests and explore whether a similar workflow might be beneficial for your work.
Create a Low Level Design (LLD) for this feature- The classes/interfaces you plan to create or modify - The functions/methods you will add or update - The signatures of these functions/methods - Any other relevant implementation details
Get the LLD reviewed by your colleagues. This can be done either by:
Create a PR with LLD: Create the first PR that only contains the class, interface and function definations but not their implementation, if not done already in the previous step
Implement each class, interface and function in a different PR: Now that you have identified all classes, interfaces and functions, implementing each of them in a different PR will be easy and you should also be able to test the public signature of it.
During the implementation phase, it’s not uncommon to realize that adjustments to a public API are necessary, such as adding, removing, or modifying function arguments or return types.
In this situation, a best practice is to:
This approach of creating small PRs has been very effective for me, and I believe it could be beneficial for you too. It does require discipline and some practice, but once you’ve integrated it into your workflow, you’ll likely find it preferable to other methods.