Reprinted: Proactive code reviews without the pain

Source: Internet
Author: User
Tags coding standards
Document directory
  • Remembering the purpose
  • A matter of Approach
  • What to do if you're a developer
  • When code reviews aren't face-to-face
  • Conclusion
  • About the author

This article is well written, reproduced. (Source of the original http://www.developer.com/java/other/article.php/3579756 ):

Valid tive code reviews without the pain
By Robert bogue

Code reviews in most organizations are a painful experience for everyone involved. the developer often feels like it's a bashing session designed to beat out their will. the development leads are often confused as to what is important to point out and what isn' t. and other developers that may be involved often use this as a chance to show how much better they can be by pointing out possible issues in someone else's code.

Code reviews, however, don't have to be painful.

Remembering the purpose

Code reviews have two purposes. their first purpose is to make sure that the code that is being produced has sufficient quality to be released. in other words, it's the acid test for whether the code shoshould be promoted to the next step in the process. code reviews are very valid tive at finding errors of all types, including those caused by poor structure, those that don't match business process, and also those simple omissions. that's why they are an executive tive litmus test for the quality of the Code.

The second purpose is as a teaching tool to help developers learn when and how to apply techniques to improve code quality, consistency, and maintainability. through thoughtfully evaluating code on a recurring basis, developers have the opportunity to learn different and potentially better ways of coding.

Code reviews often start off on the wrong foot because they are perceived as an unnecessary step that has been forced upon the developers or, in some cases, eviced that management doesn't trust the developers. neither of these perspectives is accurate. code reviews are a proven, valid way to minimize defects. whatever additional motivations the Organization has for discovery Ming code reviews, they are, at their core, an industry best practice.

A matter of Approach

One of the other ways that a code review gets off track is by the participant approaching it as though the process is designed to demonstrate who the better programmer is. code reviews often become mental jousting matches where people take shots at a target; in other words, the developer that wrote the code being reviewed. A better approach is a learning approach where the whole exercise is viewed as a forum to discuss and learn from everyone.

Saying that the approach shoshould be educational and open is one thing but creating that feeling when the history has been mental jousting matches can be quite challenging. that being said, there are a few simple things that you can do to change the approach for the better:

  1. Ask questions rather than make statements.A statement is accusatory. "You didn't follow the standard here" is an attack-whether intentional or not. The question, "What was the reasoning behind the approached you used? "Is seeking more information. obviusly, that question can't be said with a sarcastic or condescending tone; but, done correctly, it can often open the developer up to stating their thinking and then asking if there was a better way.
  2. Avoid the "why" questions.Although extremely difficult at times, avoiding the "why" questions can substantially improve the mood. just as a statement is accusatory-so is a why question. most "why" questions can be reworded to a question that doesn't include the word "why" and the results can be dramatic. for example, "Why didn't you follow the standards here... "versus" What was the reasoning behind the deviation from the standards here..."
  3. Remember to praise.The purposes of code reviews are not focused at telling developers how they can improve, and not necessarily that they did a good job. human nature is such that we want and need to be acknowledged for our successes, not just shown our faults. because development is necessarily a creative work that developers pour their soul into, it often can be close to their hearts. this makes the need for praise even more critical.
  4. Make sure you have good coding standards to reference.Code reviews find their foundation in the coding standards of the Organization. coding standards are supposed to be the shared agreement that the developers have with one another to produce quality, maintainable code. if you're discussing an item that isn' t in your coding standards, you have some work to do to get the item in the coding standards. you shoshould regularly ask yourself whether the item being discussed is in your coding standards.
  5. Make sure the discussion stays focused on the Code and not the coder.Staying focused on the Code helps keep the process from becoming personal. you're not interested in saying the person is a bad person. instead, you're looking to generate the best quality code possible.
  6. Remember that there is often more than one way to approach a solution.Although the developer might have coded something differently from how you wocould have, It isn' t necessarily wrong. the goal is quality, maintainable code. if it meets those goals and follows the coding standards, that's all you can ask.
What to do if you're a developer

The above advice is fine if you're the project or development leader who is organizing the code review, but what if you're the one who has to endure a painful code review? What can you do to make the process less painful if you're the developer who's having your code reviewed?

  1. Remember that the Code isn' t you.Development is a creative process. it's normal to get attached to your code. however, the folks who are reviewing the Code generally aren't trying to say that you're a bad developer (or person) by pointing out something that you missed, or a better way of handling things. they're doing what they're supposed to be doing by pointing out better ways. even if they're doing a bad job of conveying it, it's your responsibility to hear past the attacking comments and focus on the learning that you can get out of the process. you need to strive to not get defensive.
  2. Create a checklist for yourself of the things that the code reviews tend to focus on.Some of this checklist shocould be easy to put together. it shoshould follow the outline of the coding standards document. because it's your checklist, you can focus on the thing that you struggle with and skip the things that you rarely, if ever, have a problem. run through your code with the checklist and fix whatever you find. not only will you reduce the number of things that the team finds, You'll reduce the time to complete the code review meeting-and everyone will be happy to spend less time in the review.
  3. Help to maintain the coding standards.Offer to add to the coding standards for things discussed that aren't in the coding standards. one of the challenges that a developer has in an organization with combative code review practices is that they frequently don't know where the next problem will come from. if you document each issue into the coding standards, you can check for it with your checklist the next time you come up for code reviews. it also will help cement the concept into your mind so that you're less likely to miss opportunities to use the feedback.
When code reviews aren't face-to-face

Sure the above techniques can help you when you're sitting your SS the table from someone but how do you communicate tone and approach when you're doing code reviews through marking up the developer's code. surprisingly, it's often easier than face-to-face code reviews.

In a face-to-face code review you, have to think on your feet. you can't reread your statements and questions and then change them to be more sensitive, more precise, or more caring. the benefit of an off-line code review is most heightened at the beginning of the process. both the development leader and the developer have the opportunity to think about how to respond.

By the way, this off-line review process is the one that books (and some articles use .) this Off-line process is used all the time in the publishing world, but is strangely not frequently used for code reviews. in some ways, it can be much more effective tive than a face-to-face conversation. even if you have the ability to do meetings, you may consider moving to an off-line review to make the process better.

If you do your reviews by comments, a few special techniques are called for. They are:

  1. Put a summary comment at the top-and be positive.One of the beautiful things about a review that is done off-line is that it's possible to read through everything and make a summary statement at the top of the file. this can help set the mood of the developer so they understand whether you're thrilled, thankful, happy, and so forth. this will soften comments even if harsh at times and make them more palatable. no matter what, the initial comment shoshould contain some element of a positive message because there's something good to say about nearly every piece of code-even if it is only that it compiles. (It is syntactically correct .) setting that positive attitude is essential.
  2. Use an electronic mechanic to record the comments.Whether you export the code to a PDF file and use comments to mark it up, or copy the code into word and use Word's commenting features, make sure that you use an electronic format for comments. this is important because it doesn' t limit you to how much you can fit on a page-so you can explain more of what you mean and you can be more questioning and caring than doing hardcopy review allows.
  3. Make an upfront agreement that not every question needs to be responded.The best off-line reviews include thinking questions. questions such as "wocould it be better to implement a provider pattern here? "Don't necessarily need a response. make it clear to the developer that some comments are simply to provoke thinking. this allows you to identify areas where you want to make sure the developer is considering alternatives without raising them to the point of being an issue with the code. getting developers to think about the code they are writing doesn' t improve the quality of the code they 've already written, but it does have a long-term positive impact on code quality.
Conclusion

Code reviews are often misused and painful for everyone, but they don't have to be. some simple steps can convert torture into teaching and improve the long-term outlook for code quality in your organization.

About the author

Robert bogue, MCSE (NT4/w2k), mcsa: security, A +, network +, SERVER +, I-net +, IT project +, e-biz +, CDIA + has contributed to more than 100 Book projects and numerous other publishing projects. he was recently honored to become a Microsoft MVP for Microsoft Commerce Server and before that Microsoft Windows servers-networking. robert blogs at http://www.thorprojects.com/blog. you can reach Robert at Rob.Bogue@thorprojects.com.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.