TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Tips for reviewing code you don’t like

282 pointsby kesoralmost 6 years ago

25 comments

wickermanalmost 6 years ago
First rule about code reviewing is that you don&#x27;t tell someone how you would&#x27;ve written it, but rather try to point out pros&#x2F;cons of current vs proposed approach. It&#x27;s as easy as that. Every time I see a piece of code I don&#x27;t like I ask myself: why do I not like it?<p>I&#x27;ve gotten PR reviews with people literally writing &quot;I don&#x27;t like this&quot; even after I wrote a very detailed technical argument about my reasoning. My only approach to that is to remind them that I really don&#x27;t care about their personal preferences, because no discussion will come out of them addressing none of my technical arguments and instead relying on what their personal preference is like.
评论 #20383144 未加载
评论 #20385873 未加载
评论 #20386766 未加载
评论 #20383469 未加载
TheCapnalmost 6 years ago
I&#x27;m kind of shocked at how many recommendations are merely, &quot;have tact and don&#x27;t be a dick to your coworkers.&quot; How many code reviews are shitslinging mudfests where you guys work??<p>Now admittedly I <i>mostly</i> work on projects where I&#x27;m the sole developer so structured code reviews aren&#x27;t part of my daily routine, but during the period where I managed interns we&#x27;d do code reviews before every merge which mostly involved sitting down and going through the functions. I&#x27;d point out deficiencies and work to teach the student developers new tools&#x2F;libraries&#x2F;resources they weren&#x27;t aware of. At no point did we exchange shit like &quot;This change sucks&quot;, &quot;Can’t you see that this is obviously wrong?&quot;, or &quot;This is stupid code written by a stupid person.&quot;... all examples from an article which is also toting the &quot;Avoid hyperbole&quot; mantra. Even a single one of those snide remarks would be grounds for discipline or potentially termination if it were consistent.<p>My tip? Separate your ego from your code. If you can&#x27;t discuss criticism objectively and professionally you shouldn&#x27;t be involved in a professional career. Hostile workplaces are shit to be part of and I will never stand for that among my peers.
评论 #20386483 未加载
评论 #20388008 未加载
评论 #20386634 未加载
评论 #20387587 未加载
评论 #20388016 未加载
评论 #20387593 未加载
评论 #20386230 未加载
srfilipekalmost 6 years ago
&gt; 9. Say please<p>I actually don&#x27;t like this. Maybe it&#x27;s just me, but I always read these as being condescending, written by someone who thinks that I won&#x27;t take a suggestion without unnecessary pleasantries and&#x2F;or begging, or they&#x27;re frustrated and trying to mask it.<p>&gt; “Could you please align these variable definitions so they’re easier to read?”<p>&gt; “Could you align these variable definitions so they’re easier to read?”<p>I like the latter.
评论 #20383352 未加载
评论 #20388038 未加载
评论 #20387305 未加载
评论 #20383873 未加载
评论 #20383278 未加载
评论 #20383248 未加载
评论 #20384275 未加载
评论 #20399776 未加载
评论 #20383504 未加载
评论 #20383566 未加载
评论 #20383260 未加载
评论 #20383806 未加载
评论 #20385883 未加载
评论 #20387035 未加载
评论 #20383148 未加载
ravenstinealmost 6 years ago
My biggest problem with code reviews isn&#x27;t so much the phrasing(although it is definitely important), but the fact that they almost never has a &quot;done&quot; criterion.<p>In my opinion, if new code has nothing objectively wrong with it(no security flaws, no unacceptable design patterns, no foreseen bugs, etc.), then the author has the prerogative to merge the code. Reviews shouldn&#x27;t go on in perpetuity because different reviewers would all have written something differently than the author submitting the code. I&#x27;ve experienced this phenomenon at every company I&#x27;ve worked for at one point or another, and it&#x27;s basically a way for Waterfall to sneak its way back in to an Agile process. (not that I&#x27;m an advocate of Agile) It doesn&#x27;t happen too often, but I find it more frustrating than just about anything else.<p>Beyond some reasonable adjustments to be made in the first wave or 2 of review comments, any other non-critical changes should be separated into tickets for the next sprint or simply be labeled as DIY or &quot;do it yourself&quot;. If you want something done, but there&#x27;s no actual standard for doing it on your team, then ordering people to write things your way via code review is really just a form of <i>backseat coding</i>.<p>My code is never perfect, but that doesn&#x27;t mean I want to change variable names, swap out libraries, or use different approaches merely because someone else prefers them that way. You think the variables should have different names? Wonderful! <i>Go do it yourself</i>. I&#x27;m not trying to be rude, but I&#x27;ve got <i>other shit to do</i>, and the software already works beautifully.
评论 #20383837 未加载
评论 #20383557 未加载
评论 #20383894 未加载
评论 #20383428 未加载
评论 #20383461 未加载
评论 #20383973 未加载
评论 #20385122 未加载
评论 #20387439 未加载
评论 #20383468 未加载
pkambalmost 6 years ago
The problem I have with most similar articles&#x2F;comments is that the only two options for Code Review now seem to be:<p>- point out strict violations of the team&#x27;s enshrined code style guidelines<p>- accept any and all code as-is, so long as there are no &quot;bugs&quot; or performance issues<p>Which, at that point, why are we even doing PRs? Unit test and lint...<p>When I receive a Code Review I want to know about the function that reduces my 10 lines to 1. I want someone to notice that my git mistake introduced a bunch of unneeded diff noise. I want to change variable names that are confusing to the first reviewer, because that means they&#x27;ll be confusing to me when I read the code again next month.<p>Give me the development &quot;human factors&quot; in the code review. Some of that will be subjective and that&#x27;s ok.
评论 #20383729 未加载
评论 #20385159 未加载
评论 #20383776 未加载
JamesBarneyalmost 6 years ago
I feel like code reviews comments should be of several types. 1. There is a bug in this code(most important) 2. This violates the norms on the project 3. This is less maintainable because it can cause a future bug(two pieces of code in different that need to be consistent) 4. I personally had trouble understanding this code, here&#x27;s what took me a while to understand. Would you mind adding a comment or temp variable to speed this up. 5. Here&#x27;s a cleaner way to do it(totally in writers court whether or not they implement this unless they&#x27;re a jr. dev.<p>I make a lot less code review comments than I used to because I&#x27;ve seen too many bugs introduced by fairly innocuous looking code review changes and the amount of bikeshedding that can go into code reviews comments that will likely never materially effect the application.
评论 #20384794 未加载
Trasteralmost 6 years ago
This seems like a pretty good list, I managed a team previously where they would make these mistakes in pretty much every code review - and the result of one engineer being nasty during a code review was very quickly a culture where code reviews were an opportunity to settle scores and showboat rather than an actual functional process.<p>A lot of this advice could be boiled down to &quot;Would you make this comment on reddit, or would you say it to your colleague&#x27;s face?&quot;<p>The only thing I would add is:<p>&gt;If a submission is too large to be reasonably reviewed, it is okay to let the submitter know right away. Keep moving forward.<p>Doesn&#x27;t seem right to me - or atleast the focus really should be making sure that no one submits code for review that&#x27;s too big for review, and that means early feedback about a feature getting too complex and breaking it down. It&#x27;s much easier to go into a problem saying &quot;I&#x27;m going to do X, it&#x27;s going to be huge, so I&#x27;ll do A then B then C and submit them separately&quot;. If a submission is too big to reivew it&#x27;s probably non-trivial to go back and break up so that can be quite annoying.
评论 #20384016 未加载
alexandercrohdealmost 6 years ago
Honestly, in my opinion, the fact that this type of thing can even happen suggests the format of code-review has a problem. I propose it&#x27;s better to:<p>1. Sit at the desk of the person and pair-code review. Helps avoid basic misunderstadnings, and also is more private that a permanent written record where people may feel defensive about their choices. Also it&#x27;s easier for a lot of people to be rude through the internet.<p>2. Write in small notes if any must-address concerns arise and are agreed-upon (e.g. &quot;Security?&quot;, &quot;duplicates function x&quot;)<p>If your devs can&#x27;t interact face-to-face, then I think you&#x27;ve got major cultural problems or hired the wrong devs.
评论 #20383198 未加载
评论 #20383527 未加载
评论 #20383092 未加载
gwbas1calmost 6 years ago
I review a LOT of code, and honestly, I didn&#x27;t find this article helpful. It&#x27;s common sense on how to behave in a civil manner, but it doesn&#x27;t really help with having effective code reviews.<p>Code reviews accomplish a few things:<p>- They are primarily a <i>discussion</i> about code changes. (&quot;Why did you do this?&quot;<p>- They help onboard new members of the team, both in terms of how to work most effectively with the code, and with style. (No style guide is 100% exhaustive, &quot;We normally name variables for that fooBar, not barFoo.&quot;)<p>- They help team members learn from each other. (&quot;That&#x27;s a cool new function in the new version of XYZ library!&quot;)<p>- They help enforce good engineering practice. (&quot;I&#x27;m not merging that until you write tests.&quot;)<p>- They help make code more readable. (&quot;Please add a comment here, and rename that method to DoSomething.&quot;)<p>- They also quickly identify people who shouldn&#x27;t be part of the team. Everyone sees that someone moves slowly in a pull request, or that someone resists cleaning up sloppy code.<p>The thing with people who resist cleaning up their sloppy code is that it shows to management. This happens when everyone else in the team gets their pull requests merged quickly, and one person&#x27;s pull requests pile up with lots of minor comments.
评论 #20386779 未加载
tawat987almost 6 years ago
I disagree with the basic premise of the article that maintainers are obliged to merge code changes by default.<p>One reason is that the maintenance burden falls on more than just the author, so there needs to be some consideration on whether it is maintainable and whether the people involved are willing and able to maintain it.<p>Particularly if the change adds a public API or behavior, it may have to be maintained for the life of the codebase.<p>Also, some projects have very high reliability expectations and you have to assume that code is broken until proven otherwise. I won&#x27;t merge code until the author has demonstrated via tests, comments and clearly-written code that the change does as expected and doesn&#x27;t introduce potential issues.<p>The attitude in the article isn&#x27;t particularly conducive to the long-term health and quality of a project, since you get a bunch of authors ramming through their changes based on their agenda and end up with an inconsistent mess that nobody wants to maintain.
评论 #20388003 未加载
reallydontaskalmost 6 years ago
I use to hate receiving comments like this (the bad ones) yet I use to give them myself almost without realising it. Obviously, I was right to give them and wrong to receive them ;-&gt;<p>It took me a while to realise that the same message can be delivered in a far nicer manner, which generally leads to a lot less conflict.<p>Now it almost comes naturally to write <i>nice</i> comments that deliver the same message, namely: the code could be improved
MattyRadalmost 6 years ago
&gt; 1. Rephrase your objection as a question<p>Careful with this one. In my experience, you aren&#x27;t fooling anyone when you ask someone a question to which you yourself know the answer. It can quickly come off as condescending.<p>One helpful practice that we have is that we make a distinction between blocking and non-blocking comments. Nonblocking comments are desired changes, but aren&#x27;t required by the submitter to fix (formatting, code simplification, naming, etc). This steers people in the right direction without preventing them from getting work done. Blocking changes are critical things which must be resolved before the code gets merged (security risks, performance concerns, complexity concerns).<p>And of course, every comment should be followed with a suggestion for how to resolve it (even if it&#x27;s meeting in person). &quot;This is bad&quot; obviously doesn&#x27;t fly.
评论 #20385575 未加载
raxxorraxalmost 6 years ago
I have started to love these &quot;hey programmers, here are some tips for being a nice person for once&quot;-articles.<p>I haven&#x27;t been in too many code reviews, but my experience is that it is often taken personally if developers aren&#x27;t friends with each other. I vastly prefer unit and integration tests to measure code quality.<p>I can also understand the reluctance of maintainers to include code of a different style. Here the tips from the article probably help, but I think it happens often enough that code is rejected for non-technical issues.
评论 #20383341 未加载
tomxoralmost 6 years ago
&gt; It’s not a political or emotional argument<p>For FOSS at least, ultimately maintainers and authors are not beholden to anyone who wants to submit code, it&#x27;s perfectly ok to say NO even for political or emotional reasons... so if not in the direct context of a PR then where?<p>I think heated and unconstructive PRs probably arise as a result of pushy and entitled submitters, after a certain point authors will inevitably get fed up and abandon diplomatic approaches.
agaponalmost 6 years ago
I think that this is a very good article on code reviews: <a href="https:&#x2F;&#x2F;jml.io&#x2F;pages&#x2F;your-code-sucks-and-i-hate-you.html" rel="nofollow">https:&#x2F;&#x2F;jml.io&#x2F;pages&#x2F;your-code-sucks-and-i-hate-you.html</a>
spicyusernamealmost 6 years ago
I think the spirit of these is applicable to any situation where multiple parties need to come to consensus - i.e. try to focus on positive, respectful, inclusive, and objective modes of communication.
raverbashingalmost 6 years ago
I&#x27;ll just say that if you think Linus&#x27; comments are bad, there are much more (needlessly) rude people in LKML.<p>Linux might be incisive but he&#x27;s often right and it&#x27;s usually about an impactful issue. Some other people are just gratuitously more rude and&#x2F;or obnoxious.
评论 #20383052 未加载
fjfaasealmost 6 years ago
I have noticed that when doing a code review, I ask a lot of why questions. I want to understand why the coder has chosen for the given solution and if any other solutions were taking into consideration. I also want to know if the coder things that all use cases are covered. I find that I often happy with the answers, when I realize that the coder thought about the solution.<p>Usually, there are multiple ways to implement something and that there is no clear choice which is better. Trying to make into a black&#x2F;white problem, is not the best way to deal with the inherently grayness of software engineering. Make a fuss about coding standards, for example, is often not productive.
docker_upalmost 6 years ago
First thing before any code review is that your team&#x2F;company needs to have a coding standard. This is the first rule of engagement and eliminates most problems. Without a coding standard, code reviews quickly devolve into crap.<p>Once you have a coding standard, then the reviewer needs to differentiate between opinion and fact. If you don&#x27;t like the variable name but it conforms to the coding standard then it&#x27;s not a valid review comment. The coding standard should give some guidance as to what a variable name or function name should be.<p>If there&#x27;s a bug or if there are potential for issues then that&#x27;s what I focus on.
stuntalmost 6 years ago
I found three different reasons for people doing a bad job at code review.<p>- Not having the required soft skills to do it. - Cultural differences. Because, What is considered offensive, rude, or negative in many cultures, might be just direct in some cultures. But I do believe cultural awareness is also a soft skill. - Having a bad mentor&#x2F;peer&#x2F;environment. Many junior developers write reviews with the same style as they receive reviews.
评论 #20384007 未加载
kazinatoralmost 6 years ago
This article is complete garbage. :)<p>We absolutely must consider the non-technical aspects of a change, and it behooves us to consider them before other aspects.<p>Changes are often driven by new requirements. If we approve the change, we are approving the adoption of those requirements.<p>There isn&#x27;t always a technical reason for such an adoption other than &quot;someone wants it that way&quot;.<p>Based on this article, I mustn&#x27;t reject, for instance, GPL-ed code being added to a BSD-licensed program. There is no <i>technical</i> argument against it. We can just switch everything to the GPL license and march forward; what&#x27;s the problem? Can we put religion aside and just discuss the code?<p>There also no technical reason why a compiler shouldn&#x27;t have a --tetris option for playing a little game on the text console. No wait, I didn&#x27;t say anything about text; we can just link in SDL and have it graphical! Anyway, can we just discuss the best way to do this, and not emotional debates about whether or not to do it?<p>So, &quot;someone wants it that way&quot;? Whooptee doo, so effin&#x27; what? Let them fork the code.
Double_a_92almost 6 years ago
The most annoying thing is when the reviewer doesn&#x27;t recognise the complexity of some problem, and just insists on doing it in some &quot;simple&quot; way that doesn&#x27;t solve the whole problem.<p>&quot;Oh you spent 2 weeks figuring this solution out? Well here&#x27;s my 2 minutes of naïve ideas...&quot;
评论 #20383280 未加载
评论 #20383219 未加载
评论 #20384364 未加载
评论 #20388018 未加载
watwutalmost 6 years ago
The most infuriating code rewiev was the one where I ended up with code that I considered worst then my original one.<p>The second most infuriating one was series where I had to rewrite code because rewiever did not knew syntax I used amd claimed it is difficult to read. Three weeks later he was forcing me to use that same syntax - because he found some blog where he learned it so it became necessary. Like what the hell.
thanatos519almost 6 years ago
I was expecting a way to receive &quot;tips&quot; (small cash payments) for reviewing code ... :&#x2F;
评论 #20386404 未加载
lmmalmost 6 years ago
Most of the advice seems to amount to watering down one&#x27;s criticism. If we do that, won&#x27;t the result be accepting less-good code into our projects? Is that the outcome we want?
评论 #20382885 未加载
评论 #20382873 未加载
评论 #20382851 未加载
评论 #20382911 未加载
评论 #20382881 未加载
评论 #20382921 未加载
评论 #20382828 未加载
评论 #20382935 未加载
评论 #20382830 未加载
评论 #20382850 未加载
评论 #20388027 未加载