Before I ask for a review on a PR, I make sure that my code is production-ready and fully reviewed by me. I developed this mindset by having to review my own PRs and having no code review safety net.
If you adopt this mindset, your code will be less buggy, and future-you will be thankful because of how clear your code is.
If you have reviewers, their PR comments will have more substance, if they have reason to write anything at all.
Re-read your code changes in a PR as if you were reviewing it for the first time. This is not unlike cleaning up for a house guest. Is there a confusing corner of code? Fix it! Future-you will be thankful you did.
If you have a reviewer, only have them look at your PR once you have given your full stamp of approval on the code legibility and functionality.
This isn't to encourage coders working in silos. This is to encourage taking responsibility for the code you have chosen to write.
Ask questions as you write code on how it should be written if you're not sure. Confirm the code does what you and everyone expects it to do as you're solving problems.
(and PRs in general)
- Write code quickly that does everything you want it to do (locally)
- Do a clean up pass (locally)
- Be happy with the functionality of the code (locally)
- Push your branch
- Create a PR (but don't yet ask for a reviewer)
- Read your code changes as if you were reviewing it for the first time
- If anything is unclear as you read... change it!
- Rename vars/funcs
- Create functions to separate out logic, if necessary
- Check spelling and remove not needed code
- If you pause too long when reading your code after doing the above changes, write a comment
- Document your PR + testing instructions as you validate both
- Test browsers
- Run and modify tests
- Other click through cases
- When you feel that your code is production-ready...
- Ask for someone to review your PR -OR- accept your own PR
I do this on all my PRs except my for fun side projects.
I hope this method makes code reviews smoother and faster for you and your coworkers.
Do you practice this mentality when making PRs?
Have you ever been completely responsible for your code (and only you)?