How do I turn this around and build a healthy code review culture?
A couple of jobs ago, I worked somewhere with an excellent code review culture, and it began with a simple, written standard, very small, that everyone had agreed to. I now refuse to review code unless I am able to say "This code doesn't conform to the document you agreed to; it's not that I think this is bad code, it's that it doesn't meet the document that you agreed to." If there's no document to point at, no objective standard to meet or not meet, I'm not reviewing it because it's just not worth the tantrums and screaming from precious programmers.
There also need to be consequences for code that doesn't meet the document; basically, it's not ready to merge/commit until it does. There needs to be a way to allow code that violates the standard to be waived and permitted, with agreement from the developer and reviewer, with the waiver recorded so the developer feels listened to and the reviewer feels protected.
You're going to have to get buy-in for this from someone with power and authority.
What about rules for less objective things like how readable a function name is though? If someone wants to be difficult addressing code reviews, there's always plenty of subjective feedback they can do this for.
[0] https://google.github.io/styleguide/cppguide.html#Naming
I remember starting a project with close friends who knew each other well but we struggled on agreeing on some coding standard which everyone was happy.
People have different taste when it comes to formatting the code syntax and unless they really deep down agree to coding standard they may still like their previous habit they keep going back to them.
Overall I think it is tricky and I sometimes found it the argument of I like blue and you like red, what should we do now? Want to convince me to like red?
Your culture change is a problem of change management[0]
There are different model, but some example of actions, are :
* finding a sponsor
* creating a common vision of the end result and benefits, communicate it
* identify early adopters to deploy it with them
* identify people resistant to change (and why ? Is there a way to convince them ? [1])
* communicate your early success
Most of it is basically common sense, but it is good to have a kind of check list to help you establish your plan.
One thing that is important, because it is otherwise frustrating, you have to lay out very clearly what are the "coding rules" and what the code reviewer will actually check up front. If the "contract" is clear, it is easier to follow it.
The most annoying situation is written a whole bunch of code and having to rewrite everything.
[0] https://en.wikipedia.org/wiki/Change_management
[1] for example, a human tendency is to resist change because a fear of loss of power. So using that you could decide that the guy that is more resistant to change will actually be the one responsible for doing a fair share of code review.
First, we have git hooks that prevent code that doesn't pass certain standards from even being committed. Mostly, that's stuff like PEP8 and eslint, but there are a few other automated checks.
Second, we require at least one other person to review and leave a comment that says the code is acceptable to merge. Anybody can look at anybody else's pull request, and anybody else can block a pull request from being merged if they feel it is necessary. These things are also enforced by automated tools.
Finally, we have CI tools that not only run our extensive test suite (which must pass before a PR can be merged), but also re-run the linting checks.
I've never seen anyone get defensive about a comment on their PR in this environment. The result isn't perfect code (there are still some hairy spots in our code, but when one has 300K+ LOC, one expects that), but it's rarely very bad, and that's the point.
The only way to change your culture is to draw up standards and then fail any code review that does not meet the standards. Nothing goes live until it passes code review.
I'm a big fan of strong linting where failure to pass linting will fail the build.
The general reason why I feel that way isn't anything to do with readability but because linting can teach you what NOT to do and make you a better programmer.
Code reviews shouldn't be "move this comma" let linting handle that.
Code reviews can then be more "is what this is doing sensible, are the test cases covering the change, and (possibly most importantly) do I understand how this changes the application"
I worked at Ticketamster 1990-1996.
I went back in 2003. I remembered my first assignment. In 1990, the Linker at Ticketmaster that Troy wrote ran out of room because the MAP file grew too big.
In 2003, I went back a found a terrible kludge that I did in 1990 because I was stupid. In 2003, I fixed it correctly. I looked at the code and thought how beautiful it was. In 1990, I thought the code was bad.
As you get more experience, it is a little easier to read code. Take my word that all code is bad, LOL.
Personally, I don't like code that is made of 5-line functions with no rhyme nor reason spread seven levels deep.
Somebody said the smaller your functions the better. Bad advice.
God says... helices mists gewgaw's specced mesdames Lyndon's favoritism's fable's unequal apportions radioactivity's besoms thicknesses cordoned towel's spryer bobcat's suppressed Petra windscreen neckline overproduce meridians cartons prophylaxis's shoestring's retrospection's flubs amen thatcher bombshells cantankerous