8 ms·
A conjecture about code reviews
- jonathanwallace 14y agoThat's exactly what code reviews are used for at our company. You learn things you wouldn't have learned otherwise and a stylistic consensus grows bottom up as people discuss the whys of their personal style. Occasionally bugs are caught. We also timebox reviews to 30 minutes and they are asynchronous (review the last week's commits on github).
- senko 14y agoReviews are a great way for both reviewer and code author to learn, not just to check for correctness. If it were only that, the reviewer could probably go through the codebase and fix it faster (if it needed fixing). Critically, both should understand that it's the code under review, not the author of the code, to avoid defense-mode and frame discussion as "here's a problem, here's one solution, let's see if we can do better together".
- Roboprog 14y ago"This is going to go into production. Want to know how it works so you can support it?" (of course, if it looks like a support headache that needs to be preempted, that's good to know as well) Alternately, "How'd you do that?!?". Those are some of my main reasons for wanting to do code reviews.
- raganwald 14y agoWhen I was sixteen, I went to work for a newspaper in Hong Kong. It was a rag, but the editor taught me one important lesson. The key to a great story is not who, or what, or when, but why.--Bond Villain Elliot Carver I like "Why'd you do that" even more than "How." How I can get from the code. Why is going to be enlightening, entertaining, terrorizing, uplifting, or some combination of all four.
- ecopoesis 14y agoCode reviews are an antipattern and should die in a fire. They slow down the development process without bringing any benefits. Some say code reviews prevent bugs. They are wrong. Testing code and static analysis prevent bugs. Require all code to have unit tests and run them automatically. Run static analysis automatically. If you have developers who don't write tests, fire them. Code reviews only give you a false sense of security. You figure: since two people looked at it, it therefore must be good; forgetting that the reviewer just skimmed it over to get it out of their queue. Some say code reviews enforce style. Assuming you care about style: why not just have your IDE or static analysis tool enforce it for you? Some say code reviews help share knowledge. That may be true, but it should be unnecessary. Standups share knowledge. Wikis share knowledge. Comments share knowledge. Code should share knowledge. If you have code hitting trunk that every developer on your team can't understand easily and quickly, then you need to start finding new developers.
- debacle 14y agoI can write you code that will pass all static analysis tests with full code coverage and complete dependency injection that still makes you taste your lunch in the back of your throat. I think any good programmer could. > forgetting that the reviewer just skimmed it over to get it out of their queue. There's a difference between cargo cult code reviews and an actual, formal code review.
- ecopoesis 14y agoAnd what exactly is wrong with the code that passes all the tests and works? Its aesthetics offend you? Should the first priority of code be to work to just work? Beauty is only a nice-to-have feature. If the pretty way is about as fast to produce as the "lunch in the back of your throat" model, sure lets go pretty. But if it's going to cost me 50% of my developer's time, I'll take the quick and dirty every time.
- philwelch 14y agoIt's not so much about "beauty", but long-term maintainability of code makes development faster in the long run and reduces the murder rate within your dev team.
- lifeisstillgood 14y agoYeah, loads of teams I know need Group Therapy. :-) More and more I realise that great software comes out of teams that work well together, talk about the code daily and most importantly want each other to succeed. Code reviews might be a way to encourage that. But there is an honesty needed. Its often called a "collegiate" atmosphere - usually its based on the idea that everyone around the table has earned the right to be there, they all know and respect that, and importantly no-one can simply fire them or ban them arbitrarily - then you start to see honesty in code and discussions
- EvanKelly 14y agoAre you sure the word you're looking for isn't "collegial"? With respect to the term, I think "collegiate" is actually very appropriate, because the best group work I've ever done was in school. Everyone was okay if someone disagreed with their work, or didn't like it, and everyone was also okay with disagreeing with someone else.
- creat0 14y ago"focus on... not being found to be wrong" Why is that? Is there really even a "right" or wrong" in this process? Isn't it more of a matter of being able to support your choice of design trade-offs with cogent arguments? And being able to persuade others? There is no doubt some amount of "Why" questions that a developer can ignore. The ones that come from people who have not done their homework and thus have failed to locate the (obvious) answers. But any developer who thinks he can ignore each and every "Why" question, even if he's highly competent, is not someone I would trust with really important stuff. Is it that he is afraid of being "wrong"? That he does not have a good argument to make? Is he hesistant to say, "Honestly, I don't know. That is just the solution I chose." I don't see anything "wrong" with that. No single developer is going to be able to think of everything, of every possible solution or scenario. I thought that is an important reason behind something like code review.
- spaghetti 14y agoI think code reviews are fine as long as people are learning and building rapport with each other. When either of those are missing the reviews can be a waste of time and even detrimental to working relationships. YMMV to say the least. You can find yourself working with the friendliest person who teaches you something useful every time you look over code. Or you can end up working with someone who's emotional maturity level can only go up to put it nicely. Combine the latter case with someone who isn't quite old enough to "know what they know and know what they don't know" and you have a recipe for disaster.
- narag 14y agoPersonal experience: > It worked exceptionally well. Most errors were caught at this phase, or inmediately before, when we were reading our own code just before printing it. > We had a friendly environment. > We had a clear pre-established set of rules. We just discussed what category an error fell into. > Yes! it was also a way to learn to think about code and avoid similar errors next time, but some errors ocurred again anyway. > I miss code reviews!
- joshwa 14y agoWhat was that set of rules?
- narag 14y agoThere was a document, not too long, about ten, maybe twenty pages, that covered a lot, from code formatting to cohesion, complexity, interface size... it was a very condensed summary of Code Complete with some extra material from other books. Errors were categorized as major (show-stoppers), minor (annoyances), graphical (user visible typos), design (i.e. bad layered code, fat interfaces) and style (formatting, lack or excess of comments), IIRC. There was also an authority (the boss) that was flexible enough, but had the ultimate power of solving disagreements, so we didn't get caught in endless discussions.
- danielweber 14y agoYeah, I loved them. Everyone on the team has some little thing they know that no one else does, and everyone on the team has some little gap in their knowledge. You can spread the former and diminish the latter. We didn't have any kind of rules for the reviews, but it ended up working great. That was a really nice team.
- billnguyen 14y agoCode reviews can definitely suck but sometimes the short term cost needs to be sacrificed for long term gain and this is definitely one of them in my opinion. Code reviews help enable a 'hivemind' within a project. It helps other engineers learn how to do what you do, and helps you write readable code that enables other engineers to learn what you do helping to accelerate code velocity in the end. The resultant sense of coherency in the code is immeasurable.
- tristan_juricek 14y agoMy main observation from managing a small group was that you could easily correlate the developer's skill to the feedback they gave in code review. The ones that illuminated possible bugs or ambiguities clearly stood apart from those that merely pointed out formatting inconsistencies. And by far the worst devs in the group were the guys who said "looks good". I love the group therapy metaphor. Good regular communication about what we do, properly curated, really improves self-confidence.
- joelhooks 14y agoI'm a big fan of this style of code review. Here's some thoughts[1] of mine on the subject. [1] http://joelhooks.com/blog/2012/08/01/code-review-how-to-make-friends-and-influence-developers/ http://joelhooks.com/blog/2012/08/01/code-review-how-to-make...
- wpietri 14y agoTo me, one of the best things about pair programming is the non-confrontational, discussion-spawning nature of it. Code reviews are by definition a bit judge-y, and they catch a lot of issues after the code is already written, which yields a certain reluctance to change. When I'm pairing on something, it's rare to get in the my code vs your code thing. It's almost always our code, our ideas.
- btilly 14y agoFacts about code reviews. 1. According to research, there is no more cost-effective method of bug detection known than careful code review. (Steve McConnell's Rapid Development cites internal IBM statistics, but I completely believe it.) This is before you get to any other benefits, such as cross training, code consistency, etc. 2. According to widely reported experience for over 50 years, there is no faster way to get a lot of programmers upset than to review their code. Therefore a primary goal in code review is to avoid conflict. The following principles have been found to help. 1. Do not involve management. When people have reason to believe that their manager will see the result of code review, the odds of defensive behavior skyrockets. 2. Review only small pieces. If you find a problem in a small piece, it can be easily fixed, you move on. Reviewing a big piece is a lot more work, and fixing even a minor design flaw can be a lot of work to redo. 3. Make reviews fast. If you don't want people to write a lot of code without getting any of it reviewed, then you cannot make them take a long time to review said code. 4. Make reviews required. If people don't have to do them, they won't. And the ones who are most likely to skip are the ones whom, 6 months later, you'll wish had. In this spirit you might consider http://code.google.com/p/rietveld/ http://code.google.com/p/rietveld/ as a way to make sure that your team reviews early, reviews often, and reviews in small chunks. (Some will love it, some will hate it. Your source code quality will improve though.)
- jff 14y agoWe've found Gerrit (a git equivalent of Rietveld code review) to be significantly more usable. We were probably using it wrong, but it seemed like there wasn't a week that went by where we didn't have to re-initialize a local repo because Code Review had gone off the rails.
- isb 14y agoIn my experience, code reviews get contentious when there is subjective feedback involved for e.g. naming or class design. In that case, it helps to discuss and resolve the issues in person. Plain correctness errors or formatting issues get resolved quickly over email. Some other things from personal experience: 1. A thorough code review is time consuming but the team will appreciate it despite the disagreements. 2. Be polite and put forth your feedback with clarity and based on facts. 3. Practice what you preach - follow the same quality standards that you expect of others.
- raymondh 14y agoI've had good success doing public code review sessions at conferences where the goal was simply to generate discussion points rather than to catch errors. The discussion center around how to use the language more effectively and sometime venture into architectural issues.
- mjcohenw 14y agoWhen I participated in code reviews (of C code) when I worked at an aerospace company, I was the ONLY one who actually reviewed the code and I always found a few serious errors.
- codeonfire 14y agoMandatory code reviews are about politics and efficacy. There's many people in the programming profession who maintain the appearance of producing a lot of software. However, when you view their large number of commits, you see they do very little or nothing at all. These people don't want their competitors creating a lot of software so they will try to manipulate the politics towards a belief that in all cases: 1. a high volume of very small commits are better than a low volume of large commits regardless of the functionality they provide. 2. Number of commits is an effective metric for productivity and contribution. 3. very small amounts of code are much better than large amounts of code regardless of the functionality it provides. Code is evil, so the person that produces less of it is more saintly. 4. mandatory code reviews will find lots of bugs. Naturally, they turn into complaints about spaces and formatting. EVERY TIME. These are only true in a very limited set of circumstances. One example is when working in maintenance on an existing project. Small changes are appropriate because the product is finished. The reality is they are trying to prevent productivity and efficacy of other developers, just as a business would try to increase the costs of their competitors down the street. PHBs aren't able to understand the impact of commits and new code, and will judge productivity by number of commits, large or small, and code review complaints rather than large amounts of working, tested software. Less scrupulous people definitely try to take advantage of this in a political corporate environment.
- keypusher 14y agoOur formal policy is that at least one other team member must review a change before it is checked in. My impressions: 1. Many problems get fixed before the review even goes out. When you know others are going to be looking at the code, you tend to take a much closer look before sending it out. Also, you tend to clean up those quick hacks you put in to "just make it work". 2. It keeps the team informed. There's always at least one other person out there that knows what you have been working on. This gives you someone to bounce ideas off, but it also keeps a team together, and forces people out of getting silo'd into one particular area. 3. It is often more valuable to send out a review before it's done. If you are working on a new framework / library / class, it's better to design and prototype it, then send out a review to some people for feedback instead of waiting until you are done. They might point you in a different direction, or offer criticism, but it's much better to hear that before you have spent weeks on implementation than after. 4. Make the review process universal. If it isn't required, people won't do it. And it should be required for everyone, not just the new guys. Senior people can still learn things too, and if they are really writing great code then it should be shared with the team as an example of how to do things right. 5. Make the review process painless. Make it easy for people to generate diffs that can be shared and easy to comment, there are good tools out there for this. If the barrier to checking in changes is too high, a lot of easy fixes will get ignored because people just can't be bothered.
- noss 14y agoI have done code reviews in a scrum team setting. Often there are tasks that only one team member will implement, it would simply be too many chefs to have two developers on it, and the others are needed to implement other things. What we found very useful is to do a pre-review of the existing code to discuss how it works, but this after everyone have done their own one-hour self-study of the code (actually, self-study time tends to be until one guy interrupts saying he grok it and can describe it). Then we discuss the approach for implementation, but only one guy go ahead and implement it. The other developers have similar reviews on their areas. Afterwards, when it has been implemented, we all come together and look at the implemented solution, again first with self study of the commits, then review sitting in front of the developers desk. By only being involved as a reviewer, you get a very good understanding of the implementation. You understand not only how it works, but why it was implemented that way. It also leads to more "talk about the code" in the team. Everybody gets a common understanding of some area, you can talk about code improvements.