Live data from Hacker News

Confessions of a programmer: I hate code review (2010)

blog.nelhage.com

121–130 of 165 posts

Re: Confessions of a programmer: I hate code review (2010)

#121
post #7

I love code-reviews. With the right people, they can be useful both to achieve high-standards of code quality and also improve your own engineering process. The requirements are quite high, I think you need some combination of the following: 1. Both reviewer and reviewee are focusing on getting the best outcome possible, in good faith and with generosity. 2. The reviewer concedes that there can be equally valid appro…

Great points. Regarding point 2: > 2. The reviewer concedes that there can be equally valid approaches to a given problem or taste wrt. aesthetics. They do not try to gratuitously force their style upon the reviewee. The reciprocal must hold as well. If my code is being reviewed, and the reviewer has opinions about how they would do it, I like it when they share their preference but also 1. consider if the code as su…

I try to never block correct code. I can usually find a few things that should definitely be changed (needs more comments, delete unreachable code, remove unnecessary/unhelpful extra variables, etc), so everything else is suggestion.

Usually the submitter takes my advice, but sometimes I am educated in the process (I usually ask for better comments in this case).

Re: Confessions of a programmer: I hate code review (2010)

#122
post #116

Earlier quoted context omitted.

For us, a failing unit test is almost always a bug. Lots of people write terrible unit tests. Too much mocking, asserting methods called, etc. Brittle. Test the edge of your public interface. Supporting methods only need specific unit tests if they are sufficiently complex. If your unit's interface changes or it's behavior changes, it should fail. That is a good thing.

think there is a lot of religious-like thinking when it comes down to tests: many people swear by them even against all the day to day proof to the contrary that they are really not that useful at the application level. I think if we are shipping a framework to thousands of users its great that it has unit tests, but if its an in-house application built by a team of 10 developers, I doubt that the tests are doing any…

Usually "unit tests" should be for verifying error code paths. These are valuable at the library/package level and maybe at some level of internal integration. 100% code coverage is likely useless most of the time. At the application level, testing user inputs to user expectations is highly valuable (perhaps more so than unit tests in a lot of contexts). It is this integration/acceptance testing that any application with users should have under automation. Any codebase lacking that risks breaking or regression at the cost of user experience (which, depending on your app might be a fair trade off).

Re: Confessions of a programmer: I hate code review (2010)

#123
Code review aren’t meant to find defects- they are meant to prevent them. Every study I’ve seen on code or peer review effectiveness (and there are many) demonstrates that when code reviews are added into an orgs development process, product defects are reduced, and reduced by far more than what is accounted for in bugs directly filled in code reviews. Knowing that code is going to be reviewed and/or having to explain that code changes the way developers write code to begin with, for the better.

I’m a bit of a code review evangelist, so I’m surprised at the amount of negativity toward code reviews. Some of it sounds a bit self centered, upset that it slows down “thier” productivity or ability to self express through code rather than the real purpose of the reviews- to improve the product and organization as a whole.

Re: Confessions of a programmer: I hate code review (2010)

#124
post #77

Earlier quoted context omitted.

Nobody expects code review to be instantaneous - that's the problem. Working on another ticket involves context switching, and context switching negatively affects the productivity. Sure, that downside is probably offset by the benefits of code reviews, but that was exactly what I said: receiving a review is beneficial, it's just a bummer that there's the downside that it's not instantaneous.

You're going to be context switching at the point you make the pull request anyway. And if you structure your day well, you can do the rest of the context switching at a point when it's not a burden anyway - such as making changes in response to code review first thing in the morning before returning to your other tickets.

Well, I guess we'll have to agree to disagree there. It's far easier to continue working on the same thing, even if I have to make a pull request (or simply have to write a commit) in between, as long as that's still related to the same change. If I have to switch between entirely different problems, that has more impact on my productivity than having to switch tasks while still working on the same problem.

Again, in practice I still do actually switch to a different problem if that allows me to get my code reviewed. It's just that I wished it didn't come with the productivity hit that I experience.

Re: Confessions of a programmer: I hate code review (2010)

#125

Earlier quoted context omitted.

so another story here: code review mandatory at last place I worked, the place had a policy of any code you push in that does not match the guidelines must be changed. Guidelines was that no em allowed, must use rem. Old part of codebase assigned to me, I found some things in CSS I improved (reuse of code, a small overflow bug) Got comment - you need to change em to be rem. I can't do that because there is em all ove…

My CSS-foo is fairly weak; what problems would em cause such that they disallow it in the code base?

Both em and rem refer to element sizing. Rem is relative to the base page font size, while em is relative to the containing element font size.

The consequence is that nested em specifications are cumulative; 1.2em of 1.2 em of 1.2em gives 1.2^3, while 1.2 rem is fixed, antwhere it is used on the page.

This is not of itself good or bad, it is behaviour. Use it to desired effect.

As examples, I prefer to specify font size within elements (header, nav, aside, article, footer) in rem, font size of contained text (h1-h6, code, blockquote, pre, generally) in em, and width of text elements in em.

This allows for less CSS (most of my styles are a few dozen selectors, often less), as relative text doesn't require respecification, and content blocks are defined in terms of sensible, reader-focused, preferable widths, padding, and margins.

Much of that is personal preference: I design around article text, mostly, not wireframes or pixel-perfect layouts. The designs also tend to be robust.

Examples:

    html, body {font-size: medium; line-height: 1.4;}
    article { font-size: 1rem, width: 40em, padding: 2em 4em }
    aside, nav { font-size: 0.9rem;}
    header, footer {font-size: 0.8rem}
    h1, h2, h3, h4, h5, h6 {margin-top: 3em; margin-bottom: 1em; font-weight: bold;}
    h1 {font-size: 2em}
    h2 {font-size: 1.6em}
    h3 {font-size: 1.4em}
    h4 {font-size: 1.2em}
    h5, h6 {font-size: 1.1em}
    .callout {font-size: 2em; width: 50%; padding: 1em; margin: 1em: margin-left:0; float: left: clear both;}
Relative sizes of h1-h6 don't need to be respecified when used in header, footer, aside, nav, or .callout elements. And in callout, they're automatically scaled to 2x 1rem * factor -- cumulative application of em sizing.

With simple DOMs, this can be useful. Complex DOMs and stylesheets may benefit from direct specification via rem.

Re: Confessions of a programmer: I hate code review (2010)

#126
What this calls for is fixing / streamlining process, and awareness of context-shift costs of path-dependent processing.

The "have multiple projects, or alternatively, 'scuttwork' model, likely makes most sense. A list of noncritical-but-evergreen tasks that don't require heavy cognitive load is useful. Shoring up docs, drilling on procedures, interviewing, studying new skills or tools, etc. (Retail has a similar concept for sales associates durring slack time.)

Another is to tighten or parallelise, and prioritise and reward the review process. Both familiarity and unfamiliarity with the code base can be useful -- quick assimilation, and fresh eyes / expanded institutional awarenesss and knowledge (plus increased Bus Number).

Re: Confessions of a programmer: I hate code review (2010)

#127
post #9

You know what I hate more than code review? Shipping bugs. The author of this piece admits that they have to change the code they write in response to comments. This means the code review is flagging areas of improvement. Surely the resulting code is better than the original code (otherwise I'd expect the author to push back on the comments instead of implementing bad suggestion). Similarly, when acting as the code r…

To me, code review is a combination of two things I would think we would try to avoid: 1. Testing implementation over behavior 2. Using a human being to test in a non-automated way

Proper test coverage and human QA to me is the most effective approach to not shipping bugs, because it really doesn't matter to the customer what the code does or doesn't look like if it runs. And I just don't believe that code review is an efficient means to catch that if user is in a state of X and tries to do Y to Z that the app blows up. That becomes most apparent when that code is running in the full context of the application, not when viewed as a git diff. A bug is so often a perfect storm of seemingly innocuous but conflicting/insufficient behavior than it is some block of code that is clearly broken at a glance.

There is something to be said about stylistic and architectural issues and code reviews do give an opportunity for asking questions and driving "better" code. But this is actually just another reason why I don't like code review. "Better" is subjective and there's always another level of "better" to be reached. If I held them to my own personal standards sometimes I'd be asking for a rewrite. So what do I do, suggest that they improve their code, but not to the full extent that I feel it could be improved?

I hate code review.

Re: Confessions of a programmer: I hate code review (2010)

#128
post #9

You know what I hate more than code review? Shipping bugs. The author of this piece admits that they have to change the code they write in response to comments. This means the code review is flagging areas of improvement. Surely the resulting code is better than the original code (otherwise I'd expect the author to push back on the comments instead of implementing bad suggestion). Similarly, when acting as the code r…

Wouldn’t bugs be caught during dev testing, or QA testing or automated testing or while running on a staging server? It seems nuts to rely on a developer looking at a code diff to catch bugs in an app, it happens sometimes but I generally think review is more about quality.

Re: Confessions of a programmer: I hate code review (2010)

#129
post #90

Earlier quoted context omitted.

What's the justification here though? Saying "my code is better than other teams' even without review" does not prove that reviews are not helpful - maybe if you get your code reviewed you'll ship even fewer bugs, and if other teams don't review they'll ship even more bugs.

Further, eliminating bugs caused by any individual code commit is not really the goal behind code reviews in the first place. Finding bugs that the user notices on immediate use is an indictment of the QA process (whether manual or automatic). Code reviews help maintain sanity in the code base, and are useful for sharing knowledge (both in terms of quality of code, and ensuring that there are at least 2 people who ha…

>Code reviews help maintain sanity in the code base

But why delay the shipment of features/fixes to the customer for any of these reasons?

If code quality and human understanding is the actual rationale, it could make more sense to review code after it has shipped. In that way, it would cease to be a bottleneck for the developers or customers. Additionally, any bugs that appear in production could be accounted for during the refactoring process.

Saying that there is value to a practice is the easy part. We're forgetting to ask when to code review and whether or not code review should ever be a blocker to other processes.

Re: Confessions of a programmer: I hate code review (2010)

#130
post #108

The arguments essentially boil down to: * "I don't have time to review people's code, I just want to code" * "I don't have time to have my code reviewed, because if it's bad I'd have to fix it" This really mirrors people's complaints about unit testing: * "I don't have time to write tests, I just want to code" * "I don't have time to run tests. If they're failing I'd have to fix it" It also mirrors the 19th century c…

The problem is that most tests break frequently not because of bugs, but because of some environment dependency that changed. The tests break and we have to fix them not because a bug was found, but because something else changed that affected the test. Most of the time spent with tests is not to catch bugs. When was the last time that you caught a significant bug with a test?

>When was the last time that you caught a significant bug with a test?

Tests only really catch bugs when you're refactoring the implementation of something while trying to keep its behavior the same. You're right, in many ways, tests exist to be broken. But they still serve their purpose. They either break because you unintentionally changed behavior and need to fix your code, or because you intentionally changed behavior and need to change your tests.

Post reply on HN