|
Conceptually, I completely agree with (6). Practically, though, I found it really hard to do in some situations. Specifically, when doing something where the solution is well known for the beginning, creating PRs which are small and easy to understand is easy. When instead I have to solve difficult problems for which I don't already know the solution beforehand, and which require writing quite a bit of complex code - eg multiple classes that work with each other, and which maybe work with some complex external system I/the team doesn't already know well - I find it difficult to split the PR into smaller chunks, because I "evolve" the separate classes together, while also doing exploratory testing. "Production ready" code comes later in the process, and at that point I usually have quite a bit of code. I noticed that people don't like reviewing the non-production-ready code, but what's the alternative? In theory, after I found out what the solution is, I could go back and rewrite it better from the beginning, but that would just require too much time. Didn't find a good answer yet. |
1) Create "research prototype" of your solution. But do not commit it or commit it into separate branch (not master).
2) Create a plan how to split that code into smaller steps. Separate refactorings that will support your new feature - from your actual feature (that changes functionality).
3) Commit refactorings separately from your main feature commit. Keep every refactoring commit as small as possible).
4) At the end commit your functionality changing feature. If possible, split it into multiple commits too.
That should help with code review.
Remember, your team will have to code review your code multiple times:
1) When you are making your commits.
2) When your code reviewer reviews it.
3) In the future, when you or other team members maintain your code and try to understand why you created code that way.
So - optimize your commit to reduce code review time (even if it increases initial code writing time).