Benefits Better code Better developers Team ownership Healthy debates
Roles
As a reviewee - provide context
As a reviewer Ask don’t tell
Ask , don’t tell
Extract method to reduce duplication
What do you think about Extracting method to reduce duplication ?
Ask, Don’t tell What do you think about… ? Did you consider… ? Can you clarify… ? Why didn’t you… ?
Questions about the code Is the code clean and modular? Can I understand the code easily? Does it use meaningful names and whitespace? Is there duplicated code? Can I provide another layer of abstraction? Is each function and module necessary? Is each function or module too long?
Optimization questions <Beware of premature optimization> Is the code efficient? Are there loops or other steps I can vectorize? Can I use better data structures to optimize any steps? Can I shorten the number of calculations needed for any steps? Can I use generators or multiprocessing to optimize any steps?
Documentation Is the documentation effective? Are inline comments concise and meaningful? Is there complex code that's missing documentation? Do functions use effective docstrings? Is the necessary project documentation provided?
Testing Is the code well tested? Does the code high test coverage? Do tests check for interesting cases? Are the tests readable? Can the tests be made more efficient?
Logging Is the logging effective? Are log messages clear, concise, and professional? Do they include all relevant and useful information? Do they use the appropriate logging level?
Try to avoid using the words "I" and "you" in your comments. You want to avoid comments that sound personal to bring the attention of the review to the code and not to themselves.
Conflict We don’t agree on the issue We don’t agree on the process
What to review? Small changes SRP Naming Complexity Test coverage
What to review? Use a checklist!
Examples?
let a = new Date (); let b = a. getHours (); if (b > 12 ) { console . log ( 'Good day.' ); } Unclear Naming Could you use more descriptive variable names than 'a' and 'b'? JAVASCRIPT
function calculateDiscount (price) { return price * 0.90 ; } function applyDiscount (price) { return price * 0.90 ; } Duplicated Code This functionality appears to be duplicated in two functions. Could we merge them into one to reduce redundancy? JAVASCRIPT
function processData (data) { // processing data data. map (d => d * 2 ); return data; } No Documentation Can you add a comment explaining what 'processData' does and perhaps why it multiplies data items by 2? JAVASCRIPT
public void ProcessData ( int [] data) { foreach ( var item in data) { if (item > 100 ) { Console.WriteLine(item); } else if (item < 50 ) { Console.WriteLine(item * 2 ); } else { Console.WriteLine(item / 2 ); } } } Overly Complex Method This method seems to handle multiple conditions; could we split this into smaller, more focused methods? C#
public int Divide ( int x, int y) { return x / y; } Lack of Error Handling What happens if 'y' is zero? Should we add error handling for that case? C#
public void LogData ( string message) { if (message.Contains( "error" )) { Console.WriteLine( "ERROR: " + message); } else { Console.WriteLine( "Info: " + message); } } Inconsistent Logging Levels Should we standardize how we log messages to ensure they align with logging levels? C#
/// <summary> /// Calculates the area of a circle given the radius. /// </summary> /// <param name="radius"> The radius of the circle. </param> /// <returns> The area of the circle. </returns> public double CalculateArea ( double radius) { return Math.PI * radius * radius; } Effective Use of Documentation and Clean Code <Seems legit, all neat and clean? C#