Things Everyone Should Do: Code Review
scientopia.org
scientopia.org
Then I went and worked for a startup video game company, the programming team was myself and one of my friends from college. We decided not to do code reviews because we were building a game engine from scratch and the churn was going to be way too high to keep up with.
You can claim that code reviews are fast, but when you're generating a couple hundred new lines of code a day that really builds up. Especially when each person is committing 5-10 times a day.
What we decided to do instead is go down to the coffee shop below our office every day and just talk about what we were working on, the problems we had run into, and what should be worked on next. As a result, we still had a lot of knowledge sharing going on without having to look at every single line of code going into the codebase.
Having a general idea of how the systems are being built and put together is _much much_ more important than going over every line of code looking for bugs.
My point, is that the knowledge sharing is what's important. We could have done code reviews, but it was actually a lot easier to just talk to each other for an hour or so a day away from the computers about the state of the project. As a hidden bonus, we also got fresh perspective on implementation ideas before any work was done, which I imagine saved countless hours.
This sort of thing is probably less feasible at larger companies, so maybe code reviews are the best way to share knowledge there, but if you're under 3-4 people I'd definitely try this approach instead.
Definitely agree, though I think it's more than just knowledge sharing - I find it nice to know that you're "accountable" to some degree when you're writing code. Someone else is probably going to have to read it at some point (whether you do formal review or not), and making that fact explicit further drives home the importance of that last 10% effort to write quality code.
I think what I've found most useful about code review (pre-commit or otherwise) is a good way to have discussions with someone in the context of the code itself. Maybe this makes less of a difference in the super early stages of a project (though I've found it pretty useful then as well), but as your changes are increasingly modifications to existing complex systems, having the surrounding context in a discussion is really helpful.
but doesn't that bring some logistical challenges? how does the reviewer look at your diffs and code if your changes haven't yet been committed? or do you commit, but you branch for every bug fix, and then merge when the review is completed? is there another clever way to do this that doesn't involve revision control?
You check it into your branch, share it, code review it, fix it... Then squash the commits if you don't want all the 'mess' in the final repo. Then finally push it into the trunk.
Personally, I've never bothered squashing. The points that you deploy the code are important, but the visual aspect of the history is not so important. On the other hand, if you want to know when and why a change was done, having the FULL history is a lot more important suddenly.
The easiest method is just passing around diffs, though more sophisticated tools exist. Review Board is one I know of off-hand, though my experience with it was not overly great. I've personally just tossed together a decent diff-viewer with a couple different view modes to account for when, say, a quick patch is sufficient vs. when you really need to see the code in context.
But this is only one solution of many. I actually have seen solutions that involve source control systems, but I've always found them to be too hacky even for me.
If your source control makes branching/merging painful enough that it's going to get in your way to do it on a regular basis you might want something different, but that seems like an argument for better source control rather than a need for clever reviewing strategies.
Having this step requires the reviewer to know which tests are relevant, which ensures that they were written or updated.
Fast forward a couple of months, Joel was talking about adding SVN to FogBugz. We were sick of SVN and had this prototype, so we polished it up, presented it, and got approval to start working on it for real.
We already use fogbugz, and I'm pushing for us to switch to hg from svn so that we can use kiln too. Code review is one of the main features that I'm using as a lever. I fear that status quo / apathy may prevail though, since there is a contingent that wants to use git and if it's not unanimous, we stay where we are. Sigh.
Btw, our current process is a skype channel that we use to post links to commits (we use trac at the moment). It actually works pretty well.
Everyone is responsible for making sure the code that hits the repo is up to scratch. Sure this means more bugs hit the repo, but reviews are not primarily about catching bugs: they are about code quality. There's always room for improvement that only other eyes catch, even when there aren't any bugs. The goal is to be bugless without code reviews and people shouldn't start trusting upon code reviews to catch their bugs.
Where I work we have a pretty simple script which diffs each file in the Perforce changelist against your local copy and sends it in an email to the team, with some pretty formatting for added/removed/changed lines.
Discussion then takes place over email, which for 99% of changes is good enough since the teams are small.
After a change has been approved, it is pushed into the CI system by Gerrit, and if/when it passes that it is pushed into the public repos.
Before that all reviews were done by passing around diff files.
[1] http://lists.qt-labs.org/public/opengov/2011-February/000260...
Check out e.g. https://secure.phabricator.com/D583 for an example of a diff for phabricator itself that has some inline comments and other input.
It's yet to be seen if this overhead is worthwhile.
Review before commit is a very low-overhead approach, and the side effects of distribution of systems knowledge and pride in your code make it a tempting alternative.
For example, our codebase was for a legacy system and there was a lot of knowledge and experience about the code that was never seen without talking to someone that had already dealt with it. So it was not uncommon to have comments about a call being really bad in a loop cause it caused an unexpected database query, or to use weak reference objects here, other such things.
I miss the way code reviews transferred institutional knowledge.
Also, I learned a lot of Eclipse shortcuts through these code reviews.
In contrast, "code review" at my next full-time job inspired dread of 3-hour all-hands meetings where a big group would go over code, line by line, ages after it was submitted to the repo.
I'm solidly behind the former process. I've come up with a checklist of "pre-commit" tasks to do before someone checks in code to one of my project repos, which generally ensures that any changes submitted are tested, and as minimal as possible.
I can't believe that's true as stated.
I am guessing "No code is put to a branch which is used by others without review or "No code is put into production without review". I can't imagine "You aren't allowed to check in things without getting signoff of others" working period.
You just can't commit it to a certain repo.
A more accurate way to state "At Google, no code, for any product, for any project, gets checked in until it gets a positive review" would be that "No code goes into production without a positive code review."
TBR.
1) Does pair programming eliminate the need for code review? 2) And those who pair, what tools do you use? I've heard Gerrit, Reviewboard, and Github itself.
Though I seem to think Github pull requests aren't very good teams since you can't seem to assign them to anybody.