--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
--
--
Totally second Matt's point. I think the key phrasing there is "make clear what the normal path of execution is".I see a lot of Chromium code / reviewers that blindly follow the "early return" rule, as in "if you have two paths that never re-converge, do an early-return in one path and move the other path out of the if statement." This means we end up refactoring code like this:if (cond1) {// Perfectly "normal" case.} else if (cond2) {// Another perfectly "normal" case.} else {// Another perfectly "normal" case.}Into this:if (cond1) {// Perfectly "normal" case.return;} else if (cond2) {// Another perfectly "normal" case.return;}// Another perfectly "normal" case.This gives an undue significance to the final condition. If all three conditions are standard behaviour (not errors or special cases), then I think it's much easier to read and add new cases if all the cases are indented at the same level.I'm a big fan of early returns, but they should be reserved for error cases and other special cases where you want to stop doing whatever algorithm you would otherwise do.
The point still stands: the third case looks unduly "more mainstream" than the first two, even though it just happens to be the last case (for now).
I've had situations where I've wanted to add a fourth case and had to indent the third case, resulting in silly diffs.