News for hackers. Stuff that matters.
Re:Google takes the pain out of code reviews, with 97% dev s... by redditor98654 on Monday December 04, 2023 @09:07PM (#38526126)
I see. I want to try and understand this because I am also trying to get better at code reviews and not come across as a dogmatic person.

I have spent almost 15 years in mostly AWS and I want to keep myself in check and make sure people don't take my suggestions as the vague "quality" as you so mention just because of my seniority.

Here is the most recent PR I did for a relatively young person in my org. Part of the PR was doing a type of snake_case to CamelCase conversion from some user inputs to some enums classes. It was done manually with String manipulation and playing with indexes etc. It also came with a bunch of unit tests to make sure the conversion was working correctly.

I put in a comment along the lines of "hey, this conversion seems like it can be done with this Apache Commons Text library; given that we are already using it in the same project in some other place, we can remove this manual code and call the library function; we can even remove the tests assuming the well-tested library is doing the right thing".

Was this comment warranted? If you think this is a reasonable comment, what computer science principle would you say it is based on?

Re:Google takes the pain out of code reviews, with 97% dev s... by withinboredom on Tuesday December 05, 2023 @03:07AM (#38528194)
There are three parts to every code review:

1. Code style: such as formatting and when to use certain things (non-negotiable and you really should automate that).

2. Working code: does the PR have a description/ticket and does the code do what it promises to do? Can we refactor anything to make it better?

3. Conventions: does the PR have tests when necessary, are there negative and positive tests? Does it pass those tests? Is there anything against the conventions? If so, bring it up with the dev and find out why, outside of the PR. Maybe they didn't know the convention or there is some legitimate reason for it. Don't be an ass and call them out for it on the PR in front of the whole team, give them the benefit of the doubt and if someone else comes along and calls them out, you can present a united front vs. forcing them to defend themselves all alone.

In this particular case:

Suggesting a library should have been done before the code was even written. At this point, I wouldn't even suggest using it without some homework for the reviewer and look at the implementation in the library.

If the library implementation covers cases not found in the code I was reviewing, I would suggest looking at that library for some inspiration and/or switching to it. I would emphasize switching to it if it is far and away from the library code; as time could be better spent elsewhere. If the new implementation looks better than the library one, I might even suggest refactoring the entire codebase to use the new implementation instead of the library and/or spending some time to open a PR with the original library and improve it.

The work has already been done. Try to capitalize on it, instead of dismissing it.

Seriously though, look at the library implementation before moving forward. I've seen some very popular libraries and frameworks be very poorly implemented in some areas but because "it's popular" people seem to think it is better. That's not always the case.

Re:Google takes the pain out of code reviews, with 97% dev s... by Arainach on Tuesday December 05, 2023 @04:47PM (#38537384)
>The work has already been done. Try to capitalize on it, instead of dismissing it.

Except it hasn't at all. This is the attitude of people who send pull requests to open-source projects and complain that they aren't accepted.

The work is integrating that code with the rest of the system, ensuring it's compatible with future plans, ensuring that it's scalable and secure, and ensuring that the whole team can understand and maintain it.

Successful projects don't just take any code that compiles and passes the tests, they are built in a thoughtful manner with high standards.

Re:Google takes the pain out of code reviews, with 97% dev s... by withinboredom on Tuesday December 05, 2023 @05:51PM (#38538065)
> This is the attitude of people who send pull requests to open-source projects and complain that they aren't accepted.

To be honest, I’m not sure how you got there from here…

> The work is integrating that code with the rest of the system, ensuring it's compatible with future plans, ensuring that it's scalable and secure, and ensuring that the whole team can understand and maintain it.

I actually suggested deprecating the library. I am not going to presume how hard that is. It might be changing 2 lines of code or 1000. No idea. That’s why we have brains though, we are able to figure these kinds of things out. As far as ensuring it’s compatible with future plans… do you honestly think a “random” maintainer of a library has your best interest at heart? That’s rather unlikely unless the maintainer happens to work for the company in question. In this particular case, it looks like someone volunteered to be that maintainer (probably due to naivety, but that’s beside the point) and they actually do have your future interests at heart.

So to say that an employee doesn’t do work aligning with their company’s goals means you have bigger (political) problems than code review problems, hence why I said they should never have started working on it in the first place. For them to work on something like this for someone to review and professionally say “wtf” is a red flag, far and beyond code reviews; which is interestingly another reason why it is waaay too late to be having these conversations in a PR. It’s a smell that something in the team is fundamentally broken.

Re:Google takes the pain out of code reviews, with 97% dev s... by Arainach on Tuesday December 05, 2023 @08:57PM (#38539615)
>To be honest, I’m not sure how you got there from here…

"I've done all this work, get put of my way and submit" is the attitude in both cases.

Congratulations, you wrote some code. It's not done until it meets team/project standards, and getting offended any time anyone has feedback makes you someone I'd never want to work with.

The default answer to code review feedback is always "sure" unless you have a strong argument otherwise. It takes way less time to implement feedback than to pretend you're Socrates and question everything.

Re:Google takes the pain out of code reviews, with 97% dev s... by withinboredom on Wednesday December 06, 2023 @02:22AM (#38541284)
> "I've done all this work, get put of my way and submit" is the attitude in both cases.

That’s quite a stretch. Nobody should be “in your way” to begin with. In a company, you are on a team and the point of a team is to work together; not get in each other’s way. That’s a sign of a dysfunctional team, which is how you end up getting team members working on the wrong thing or implementing things wrongly in the first place. Code not up to “standards” is not a reason to reject code, it’s a sign that something else is wrong on the team and that is the thing to be addressed, not the code. You aren’t going to resolve it in a code review.

I don’t know how else to say that at this point.

> The default answer to code review feedback is always "sure" unless you have a strong argument otherwise.

I’ve definitely pointed out why a deleted line needs to be kept. I would not be surprised if that someone came back to tell me why it should be deleted. As a reviewer, I lack a lot of context even if I originally wrote the code. I’d never, ever, expect someone to blindly say “sure” on a code review. I don’t write perfect code and neither do my team members, so I don’t expect a perfect reviewer.

A team works together to make the code perfect, nobody is writing mystery code and doing weird stuff without discussing it with the team first. And sure, people experiment and we review it, but with an architectural lens. Then when we are happy with the architecture, we actually implement it, together.

Re:Google takes the pain out of code reviews, with 97% dev s... by redditor98654 on Wednesday December 06, 2023 @12:52PM (#38547234)
> Suggesting a library should have been done before the code was even written.

Unless you agree on every detail before implementing anything, I don't see how this is practical. At least not in the companies I have worked in.

> The work has already been done. Try to capitalize on it, instead of dismissing it.

Not quite though. The developer may have written down some code but the work is not done. It needs to be shipped to production, monitored and supported by the oncall etc. If there is a way to not write some code and use a library, I will suggest that.

> Don't be an ass and call them out for it on the PR in front of the whole team, give them the benefit of the doubt and if someone else comes along and calls them out, you can present a united front vs. forcing them to defend themselves all alone.

If I see a PR with some key tests missing, I don't see why asking if we can add some more tests would be seen as calling them out on it. The PR is a place to record such things - may be it does not need such tests or may be it is intentionally not handled in the code etc. Why would such a discussion be seen as someone being an ass?

Why do I have to have that perfectly normal discussion in secret away from the rest of the team? We can ask questions and still be professional. Code reviews are not just for making sure code is good, but also for education - it is a good way for the other to know what is going on and also learn.

My read on this is that may be this is what happened to you - someone was being personal and attacked team members personally in the guise of a review and now you take a stance that either discuss everything before implementation in person or have separate meetings in private to suggest changes or ask questions.

I am thankful I did not have such a colleague/mentor when I started and hopefully I am not inflicting such an attitude to the new folks that are coming in now.