How to code review
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
function greet(timeOfDay) {
const messages = {
morning: 'Good morning',
afternoon: 'Good afternoon',
evening: 'Good evening'
};
console.log(messages[timeOfDay] || 'Hello');
}
Modular and Clean
<Why ask a question?>
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#
Thank you

How to code review for awesomeness and clarity

  • 1.
  • 2.
  • 3.
  • 4.
    As a reviewee- provide context
  • 5.
    As a reviewer Askdon’t tell
  • 6.
  • 7.
  • 8.
    What do youthink about Extracting method to reduce duplication?
  • 9.
    Ask, Don’t tell Whatdo you think about… ? Did you consider… ? Can you clarify… ? Why didn’t you… ?
  • 10.
    Questions about the code Isthe 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?
  • 11.
    Optimization questions <Beware of premature optimization> Isthe 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?
  • 12.
    Documentation Is the documentationeffective? 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?
  • 13.
    Testing Is the codewell tested? Does the code high test coverage? Do tests check for interesting cases? Are the tests readable? Can the tests be made more efficient?
  • 14.
    Logging Is the loggingeffective? Are log messages clear, concise, and professional? Do they include all relevant and useful information? Do they use the appropriate logging level?
  • 15.
    Try to avoidusing 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.
  • 16.
    Conflict We don’t agreeon the issue We don’t agree on the process
  • 17.
  • 18.
    What to review? Usea checklist!
  • 19.
  • 20.
    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
  • 21.
    function calculateDiscount(price) { returnprice * 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
  • 22.
    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
  • 23.
    function greet(timeOfDay) { constmessages = { morning: 'Good morning', afternoon: 'Good afternoon', evening: 'Good evening' }; console.log(messages[timeOfDay] || 'Hello'); } Modular and Clean <Why ask a question?> JAVASCRIPT
  • 24.
    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#
  • 25.
    public int Divide(intx, int y) { return x / y; } Lack of Error Handling What happens if 'y' is zero? Should we add error handling for that case? C#
  • 26.
    public void LogData(stringmessage) { 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#
  • 27.
    /// <summary> /// Calculatesthe 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#
  • 28.