Categories
Agile Development Programming Software Architecture

The 8 Levels of Code Review Pyramid : One Diagram to Remember for Code Reviews

An essential step in the software development lifecycle is code review. Code reviews are powerful means to improve code quality, establish best practices, opportunity to learn, and knowledge sharing and mentoring, as well as promotes team cohesion.

What to look for in a code review? Try to look for things such as ๐—ฑ๐—ฒ๐˜€๐—ถ๐—ด๐—ป (does this integrate well with the rest of the system and are interactions of different components make sense), ๐—ณ๐˜‚๐—ป๐—ฐ๐˜๐—ถ๐—ผ๐—ป๐—ฎ๐—น๐—ถ๐˜๐˜† (does this change is what the developer intended), ๐—ฐ๐—ผ๐—บ๐—ฝ๐—น๐—ฒ๐˜…๐—ถ๐˜๐˜† (is this code more complex than it should be), ๐—ป๐—ฎ๐—บ๐—ถ๐—ป๐—ด (is naming good?), ๐—ฒ๐—ป๐—ด. ๐—ฝ๐—ฟ๐—ถ๐—ป๐—ฐ๐—ถ๐—ฝ๐—น๐—ฒ๐˜€ (solid, kiss, dry), ๐˜๐—ฒ๐˜€๐˜๐˜€ (are different kinds of tests used appropriately, code coverage), ๐˜€๐˜๐˜†๐—น๐—ฒ (does it follow style guidelines), ๐—ฑ๐—ผ๐—ฐ๐˜‚๐—บ๐—ฒ๐—ป๐˜๐—ฎ๐˜๐—ถ๐—ผ๐—ป, etc.

Code review is a conversation, not a queue of commands.

Code review checklist

A checklist helps you to create a structured approach to code reviews. Also, they remind you of all the quality checks you need to perform to approve code into the codebase.

๐Ÿญ. ๐—ง๐—ฟ๐˜† ๐˜๐—ผ ๐—ฟ๐—ฒ๐˜ƒ๐—ถ๐—ฒ๐˜„ ๐˜†๐—ผ๐˜‚๐—ฟ ๐—ผ๐˜„๐—ป ๐—ฐ๐—ผ๐—ฑ๐—ฒ ๐—ณ๐—ถ๐—ฟ๐˜€๐˜

Before sending a code to your colleagues, try to read and understand it first. Then, search for parts that confuse you.

ย 

๐Ÿฎ. ๐—ช๐—ฟ๐—ถ๐˜๐—ฒ ๐—ฎ ๐˜€๐—ต๐—ผ๐—ฟ๐˜ ๐—ฑ๐—ฒ๐˜€๐—ฐ๐—ฟ๐—ถ๐—ฝ๐˜๐—ถ๐—ผ๐—ป ๐—ผ๐—ณ ๐˜„๐—ต๐—ฎ๐˜ ๐—ถ๐˜€ ๐—ฐ๐—ต๐—ฎ๐—ป๐—ด๐—ฒ๐—ฑ

It should explain what changes were at a high level and why those changes were made.

๐Ÿฏ. ๐—”๐˜‚๐˜๐—ผ๐—บ๐—ฎ๐˜๐—ฒ ๐˜„๐—ต๐—ฎ๐˜ ๐—ฐ๐—ฎ๐—ป ๐—ฏ๐—ฒ ๐—ฎ๐˜‚๐˜๐—ผ๐—บ๐—ฎ๐˜๐—ฒ๐—ฑ

Automate as much as you can
PMD, FindBugs, and Checkstyle are the most popular code analyzers,
Jenkins for CI-CD ,code smells and bugs (SonarQube).

๐Ÿฐ. ๐——๐—ผ๐—ปโ€™๐˜ ๐—ฟ๐˜‚๐˜€๐—ต

You need to understand what is changed in every line of it. Read multiple times if required, class by class.

๐Ÿฑ. ๐—–๐—ผ๐—บ๐—บ๐—ฒ๐—ป๐˜ ๐˜„๐—ถ๐˜๐—ต ๐—ธ๐—ถ๐—ป๐—ฑ๐—ป๐—ฒ๐˜€๐˜€

Never mention the person (you), always focus on changes as questions or suggestions and leave at least one positive comment. Explain the โ€œwhyโ€ in your comments and suggestions for improving it.

๐Ÿฒ. ๐—”๐—ฝ๐—ฝ๐—ฟ๐—ผ๐˜ƒ๐—ฒ ๐—ฃ๐—ฅ ๐˜„๐—ต๐—ฒ๐—ป ๐—ถ๐˜๐˜€ ๐—ด๐—ผ๐—ผ๐—ฑ ๐—ฒ๐—ป๐—ผ๐˜‚๐—ด๐—ต

Donโ€™t strive for perfection, but hold to high standards.

๐Ÿณ. ๐— ๐—ฎ๐—ธ๐—ฒ ๐—ฟ๐—ฒ๐˜ƒ๐—ถ๐—ฒ๐˜„๐˜€ ๐—บ๐—ฎ๐—ป๐—ฎ๐—ด๐—ฒ๐—ฎ๐—ฏ๐—น๐—ฒ ๐—ถ๐—ป ๐˜€๐—ถ๐˜‡๐—ฒ

We should limit the number of lines of code for review in one sitting. Our brains cannot process so much information at once. The ideal number of LOC is 200 to 400 lines of the core at one time, which is usually 60 to 90 minutes.

8. Review logic, not semicolons

Automation reduces the needless checks and letโ€™s you focus on the logic behind the changes rather than syntax errors and typos.

Code Review Pyramid

What is your code review process? What works for you, and what does not?

When it comes to code reviews, itโ€™s a common phenomenon that there is much focus and long-winded discussions around mundane aspects like code formatting and style, whereas important aspects (does the code change do what it is supposed to do, is it performant, is it backwards-compatible for existing clients, and many others) tend to get less attention.

To raise awareness for the issue and providing some guidance on aspects to focus on, I shared aย small visualย on Twitter the other day, which I called the โ€œCode Review Pyramidโ€. Its intention is to help putting focus on those parts which matter the most during a code review (in my opinion, anyways), and also which parts could and should be automated.

As some folks asked for a permanent, referenceable location of that resource and others wanted to have a high-res printing version, Iโ€™m putting it here again:

FAQ

  • Why is it a pyramid?

    The lower parts of the pyramid should be the foundation of a code review and take up the most part of it.

  • Hey, thatโ€™s a triangle!

    You might think so, but itโ€™s a pyramid from the side.

  • Which tool did you use for creating the drawing?

Leave a Reply Cancel reply