14

Our team has recently started conducting code reviews against each checkin.

As the team lead I'm trying to find a balance between providing too many suggestions, annoying developers and decreasing the teams output, and letting go of code I would have written differently.

Is there any evidence, study or guidance from well known sources which suggests a helpful approach?

4
  • 2
    The first question to ask yourself: why are you doing code reviews? Commented Jun 24, 2017 at 7:16
  • 1
    I'd be tempted to assign some kind of "importance" to each piece of feedback. Critical security vulnerability = very high importance. Bug = normal importance. Code formatting = zero importance (blame tools that don't auto-reformat any way you like and not the programmer).
    – Brendan
    Commented Jun 24, 2017 at 7:38
  • It might interest you
    – Laiv
    Commented Jun 24, 2017 at 10:23
  • The way a person approaches or responds to a code review says much about their ability to maintain objectivity and think critically. Sometimes developers need training for this purpose specifically. Commented Jun 26, 2017 at 23:48

5 Answers 5

15

Keep in mind the overarching goals: in the end, only working software matters

Peer review and check-in code review have the goal to improve quality. But there's nothing worse for quality than a demotivated developper. As a team lead, your role is not to endorse the code as something that you could have written yourself, but to promote teamwork and ensure the overall result.

Set a clear scope for your review

Keep in mind: it's not your code, but the team's code. So, focus on things that could lead to wrong results.

  • Don't challenge the way your developer has chosen to meet the requirements, unless you're certain it won't work (but it should already have failed the tests, no?)

  • Don't challenge for poor performance unless there is a measure that shows where the issue is. Premature optimization is the root of all evil ;-)

  • If you find a design or software structure to challenge, then ask yourself why it wasn't caught upfront! Already written code is expensive to rewrite. If this happen, it's time to review your software development and teamwork practices at least as much as the code.

  • address compliance with established coding standards. It's the most annoying topic to discuss for both the reviewer and the reviewed. When everyone agreed to use capitalized class names in your team and one guy has a class without, is it a matter of taste ? Or of teamwork effectiveness and risk ?

By the way, if you feel a coding standard is not worth to be discussed, remove it form your standards and don't waste time and energy on it.

Develop leadership: the human side of the review

As a team leader, you may find here an opportunity to develop yourself and your team, beyond the formality of a quality control:

  • Code reviews are much more pleasant for everyone, if there's a true exchange. Give your developper the opportunity also to show their skills (and yes, perhaps you could learn something new).
  • Have an open ear to criticism on design choices, or existing standards. Sometimes people can cope better with such frustrations, just because they could talk about it.
  • Coach your juniors: don't hesitate to give advices, or refactoring orientations for the next iteration. Don't do this with seniors: in another world your respective role could have switched.

Take advantage of other practices

There are a couple of things that you can avoid in code-review:

  • Use of a static code analyzer in your build chain can automate the finding of common bugs, or non portable constructs, long before the peer review. Some tools can even check for some of your coding standards.
  • If you have standards about code layout, use a pre-commit pretty-print or similar formatters to format the code as required automatically. Never spend time on something a software could do for you better and without discussing :-)
  • Finally, quality is not only ensured by review, but also by tests. If you don't use TDD yet, give it a thought independently of code review.
2
  • "Working software"? Not very useful. "Correct software" -- that is what I prefer! Commented Jun 26, 2017 at 23:46
  • @FrankHileman Indeed! And accurate, reliable, usable, performant, and fit for purpose. It's just a question of defining the term "working" appropriately ;-)
    – Christophe
    Commented Jun 27, 2017 at 5:45
3

As developers we are, the mindset should remain always open and sceptical at the same time.

Open, because we don't know when a developer may surprise us, and sceptical about our own ideas because we often forget that in software engineery there's not a single correct way to implement a solution. The rationale behind our solutions could make sense for us and make none for others. Behind a code smell there could be a great idea. Maybe, the developer didn't find the way to express it properly.

Due to we (humans) are terrible at communicating, don't make false assumptions, be willing to ask to the code owner about the code you are reviewing. If he/she failed at coding the idea under the company' standars, as lead developer be willing to guide him/her too.

Here the subjective approach. The objective approach, IMO, is very well explained in this question.

In addition to the link above, the set of objectives to be achived (maintainability, readability, portability, high cohesion, loose coupling, etc.) are not necessarily the Ten Commandments. You (the team) should be able to adapt these objectives to a point where the balance between quality and productivity makes the job confortable and "habitable for developers".

I would suggest the usage of static code analysis tools for measuring the progress of the quality according to these objectives. Tools like SonarQube provide us with Quality Gates and Quality Profiles that can be customized according to our priorities. It also provides us with a issue tracker, where developers can be targeted with issues related to code smell, bugs, doubtful practices, etc.

These kind of tools can be a good starting point, but as I said keep yourself sceptic. You could find some rules in Sonar to be meaningless for you, so feel free to ignore them or remove them from your quality profile.

2

Meddling with developer's code for cosmetic changes will demotivate the developer but in absolute circumstances it has to be done. The lead has to find the balance between providing useful code review and learning to let go of minor shortcomings. https://blog.smartbear.com/sqc/for-the-new-team-lead-the-first-six-things-you-should-know/

3
  • what are the "absolute circumstances" that require cosmetic changes?
    – Ewan
    Commented Jun 24, 2017 at 7:50
  • 1
    When coding guidelines have been not followed, code design flaws which can cause memory leaks are instances when the lead cannot afford to let go. Commented Jun 24, 2017 at 7:55
  • Your link is dead Commented Aug 23, 2018 at 7:28
1

Some things to keep in mind:

  1. It is about psychology as much as about technology, so there is no golden rule here.
  2. What is about people is not just about knowledge but also about culture and position in hierarchy.
  3. If this is a "long" game (stable and established company), well integrated team where people trust each other usually has higher value than the code under review. It should not be used to force things that are not absolutely required to proceed. Devil is in the details...
  4. If this is a "short" game (side project, R&D, lots of freelancers in a group) costs of CR often overcome adventages comming from doing them. And attitude should be "just make it wok"
-4

There are only two things that matter.

  1. Are there automated tests for all requirements?
  2. Do they all pass?

Everything else is cosmetic and should be argued about over beer rather than enforced as a gate.

If you follow this view, then it limits you to a narrow area of focus.

Are the requirements good? Which ideally you should know before starting the task, ie performance, security etc should all be in there

Are the tests good tests? Any missed edge cases, are they testing the requirement well etc. Ultimately: Can you write a test which is for an existing requirement but which will fail?

2
  • 3
    Would you say that code without any line breaks, with only single letter variable names and otherwise obfuscated is acceptable? All the tests would pass, but it's not maintainable. Commented Jun 24, 2017 at 8:08
  • In a code review? yes. As soon as you get into naming its all subjective. You choose an extreme example, but there are plenty of cases where people use single letter iterators or condense code into single line functions which would be considered good practice
    – Ewan
    Commented Jun 24, 2017 at 8:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.