News for hackers. Stuff that matters.
Re:Don’t Teach During Code Reviews by moomoo11 on Sunday February 05, 2023 @04:38PM (#34669740)
Hm. So I just give my opinion on code reviews by just giving explanation, link to a documentation, along with my recommended change.

My job is to ship software, and as an engineer/team lead it is my job to ensure the code we ship is maintainable, tested, and documented as far as any gotchas or hacks go. Ideally we want to improve the code base as well, especially when dealing with legacy code.

I think people take code reviews way too personally. Like, my priority is to ensure I don’t have headaches down the line and when I work with peers or more experience people, I barely leave any comments or get any on my PRs for them since we are all on the same wavelength and for the most part know what we are doing.

A junior engineer is a… junior engineer. They are going to have a lot of comments telling them how to write better code and a good suggestion will include a code suggestion and links to read.

It’s how they will get better, and for bigger tickets or super juniors, I sometimes pair with them to go through their ticket together.

At a certain level you just know how to identify patterns and understand how to build good software.

Juniors tend to just write yolo shit code or add more shit to a legacy shitcode repo instead of trying to improve it. They’ll add to the mess instead of writing a new clean layer on top to which we can easily maintain and modify. But that’s why you have to show them.

The only thing that helps people get better is time, being humble, and being genuinely interested themselves in becoming better at their craft. I remember my junior engineer days, and seeing my PRs filled with comments. But if I didn’t have those I don’t think I’d have leveled up so fast.

Re:Don’t Teach During Code Reviews by doutunlined on Sunday February 05, 2023 @05:28PM (#34670356)
Your comment implies juniors are only juniors for a temporary amount of time. I've worked with many SWEs (some with years of FAANG experience) who consistently code like juniors. They are aware of things like the separation of concerns, but as soon as they run into a situation wheres its easier for them to leak one layer's concern into another they will do so. Consistently doing this over months erodes the quality of a codebase.
Re:Don’t Teach During Code Reviews by simplotek on Sunday February 05, 2023 @06:33PM (#34671034)
> They are aware of things like the separation of concerns, but as soon as they run into a situation wheres its easier for them to leak one layer's concern into another they will do so.

That says nothing without context.

If you want to move fast then it's ok to break things, and leaking layers is far from a non-negotiating tradeoff. Software is soft, and you can always revisit a piece of code to refactor it to suit someone's architectural tastes.

It makes no sense to criticize someone for focusing where it matters the most and actually deliver critical features without delay if the tradeoff is some legacy debt, and that by no mean implies they're junior.

One important skill of a senior is being able to keep their eyes on the prize and be smart about tradeoffs. Prioritizing subjective opinions over software architecture over delivering value is more in line with a junior way of thinking about software than not, and to me doesn't sound like a position to criticize others.

Re:Don’t Teach During Code Reviews by bcrosby95 on Sunday February 05, 2023 @07:12PM (#34671428)
I'm gonna call bullshit on all of this. The time tax on not leaking layers in an application that doesn't already leak layers is nearly zero.

The problem is people don't want to expend the very minor extra amount of effort.

So you do it once. Then the next person does it because hey we already do it there so the code is not even subjectively worse, it's objectively the same, cuz you already crossed that line.

After a while you have a giant festering pile of shit that you just keep making bigger and bigger and now people are talking about rewriting it.

In my experience you start actively losing velocity in this situation very quickly. If you're doing this when you still your have 3+ months on a project, you're likely making poor decisions.

I'm not saying you need to constantly gold plate your architecture. But it should be palatable.

The subjective part is what is palatable. But I don't know anyone who thinks steaming turdpiles are palatable.

Re:Don’t Teach During Code Reviews by turdprincess on Sunday February 05, 2023 @08:29PM (#34672062)
In my experience, codebases never maintain their level of quality. Unless you are taking deliberate action to improve the codebase with every commit, it's actively getting worse like you described above.

The interesting thing is that this isn't a technical problem, it's a human problem. Most folks want to clock in, do their job and clock out, and going the extra mile to improve things isn't worth the effort.

I think its the same human tendency that leaves so much pee on the toilet floor - some humans will clean up their own, but almost none will clean up someone else's.

Re:Don’t Teach During Code Reviews by mixedCase on Sunday February 05, 2023 @10:41PM (#34673045)
And that's why you don't let any bullshit in, exercise eternal vigilance and rely on static analysis tools to stem the turd wave in an automatic fashion as much as you can.

The solution is not to accept "it is what it is".

Re:Don’t Teach During Code Reviews by ornornor on Monday February 06, 2023 @02:15AM (#34674307)
> Most folks want to clock in, do their job and clock out, and going the extra mile to improve things isn't worth the effort.

I suspect this is because it’s almost never rewarded. Either because nobody up the chain of command understands and values quality beyond “it’s working and making us money right now so it’s fine” and also because doing things right is tiring. Why should I spend energy on this and not have that energy when I’m off the clock if I’m not going to get more money/recognition/time off for it and I’ll probably get laid off or move on in a couple years anyway.

I don’t think anyone deliberately starts a job or task thinking they’ll do the absolute minimum. People generally want to do their best but the system moderates this desire and that’s the result.

I don’t really have a solution, just pointing it out.

Re:Don’t Teach During Code Reviews by awill88 on Monday February 06, 2023 @03:56AM (#34675012)
I too like to use the metaphor a codebase is like a public toliet. Gotta clean it or it’s gonna get gross!
Re:Don’t Teach During Code Reviews by andrewflnr on Sunday February 05, 2023 @10:45PM (#34673068)
I mostly agree, BUT, it's very possible to end up with a situation where your current layers, even if they don't leak, are ill-designed for the feature you're working on. It can be a lot of work at that point to keep it non-leaking. You should still do it, but it won't be "nearly zero" cost.
Re:Don’t Teach During Code Reviews by theonething on Monday February 06, 2023 @02:17AM (#34674324)
In my professional experience of > 10 years, that is 95% of codebases. Maybe I'm unlucky?
Re:Don’t Teach During Code Reviews by simplotek on Monday February 06, 2023 @02:45AM (#34674502)
> I'm gonna call bullshit on all of this. The time tax on not leaking layers in an application that doesn't already leak layers is nearly zero.

The time tax is paid by not delivering a feature. Architecture is supposed to be there to help you, not fail deadlines.

Also, it seems you completely failed to read or get what I wrote. My point was that if a PR delivers a feature without defects then your team is far better off if you accept the PR and refactor later when you can spare the time then it is if you throw a hissy fit and refuse to get the feature done if you don't get your way. You are paid to create value which is in delivering features and fixing bugs. Architecture is supposed to be there to help you.

Think about it for a second. If your architectural purity demands a hefty refactor, is that a good justification to postpone a bug fix or delivering a feature? No, it isn't.

> The problem is people don't want to expend the very minor extra amount of effort.

Except that most time it isn't minor.

You have to pass interfaces throughout a bunch of components, which require updating all sorts of tests, and result in a large code footprint.

> After a while you have a giant festering pile of shit (...)

That only happens if you're incompetent at your job and fail to do the most basic maintenance tasks in your code base.

Look at what you're trying to claim. It's supposedly easy and trouble-free to put together a PR that respects your personal notion of what the software architecture should be. Yet, the work to refactor code that breaks it is so insurmountable that you're no longer able to refactor it back to shape?

Which one is it then?

It looks like the FANG engineer you tried to badmouth had a firmer grasp on things and on what it matters the most than you do.

Re:Don’t Teach During Code Reviews by bcrosby95 on Monday February 06, 2023 @05:01PM (#34685077)
> The time tax is paid by not delivering a feature. Architecture is supposed to be there to help you, not fail deadlines.

Most deadlines are artificial. If it's not artificial, yeah, you're going to have to sacrifice something for the sake of the real deadline. But make no mistake - you are sacrificing something.

> Also, it seems you completely failed to read or get what I wrote. My point was that if a PR delivers a feature without defects then your team is far better off if you accept the PR and refactor later when you can spare the time

You don't ever have spare time. When you finish a feature there's another waiting for you. At least, that's how it works literally everywhere I've worked. Working this way is just another form of over-promising and under-delivering.

> then it is if you throw a hissy fit and refuse to get the feature done if you don't get your way

Rejecting a change doesn't mean you're throwing a hissy fit.

> You are paid to create value which is in delivering features and fixing bugs. Architecture is supposed to be there to help you.

It does help you. In the medium to longer term. In the short term, literally any standard out there will slow you down - unit tests, CI/CD, shit - testing at all. It all slows you down. It doesn't mean we should just code like its 90s era PHP - the fact that we don't should be a strong signal about the value of this whole hypothesis you have going here.

> You have to pass interfaces throughout a bunch of components, which require updating all sorts of tests, and result in a large code footprint.

Funny. Your tests are slowing you down, why don't you just comment them out to get your feature in?

> Look at what you're trying to claim. It's supposedly easy and trouble-free to put together a PR that respects your personal notion of what the software architecture should be.

It's not actually just personal. We have unit tests that enforce certain architectural rules.

> Yet, the work to refactor code that breaks it is so insurmountable that you're no longer able to refactor it back to shape?

If you don't follow standards, as a senior software engineer, why should anyone else? If no one is following standards, how large do you think that shitpile is going to get? And do you really think its just as easy to fix something after the fact? Of course, if you don't know how something should be, that's one thing. But knowing how it should be and just skipping it altogether is quite another.

Why are you even refactoring for reasons you view as subjective? I don't do subjective refactorings. Despite what you claim, at the point of a change, much of this stuff is very not subjective. If you show any developer a function call before a feature was added, and what it looks like after its been hacked it in some fucked way, no one is going to say the fucked version is better.

> It looks like the FANG engineer you tried to badmouth had a firmer grasp on things and on what it matters the most than you do.

Well maybe you're just so smart its trivial for you to navigate this stuff. If so, continue by all means. Until then, us mere mortals will have to adopt standards so our codebases don't outpace our ability to understand it.

Re:Don’t Teach During Code Reviews by fshbbdssbbgdd on Sunday February 05, 2023 @08:30PM (#34672075)
This possibly be true in some case, but I find it to mostly be wrong. The best time to fix up some code is when you are already modifying it, because that’s when you are already fully in context to understand the effects. Going back later to clean stuff up is much less likely, because you have to pay that marginal comprehension cost again and again for each issue you fix (and are less likely to even notice the problem). If you’re making this excuse, that suggests you have internalized that it’s ok to makes your codebase worse and you are probably degrading it progressively.
Re:Don’t Teach During Code Reviews by thih9 on Sunday February 05, 2023 @10:39PM (#34673017)
> This possibly be true in some case, but I find it to mostly be wrong.

Yes. That’s why it’s an important skill for an engineer to know when to make that tradeoff.

Sounds like you’re agreeing with the grandparent?

Re:Don’t Teach During Code Reviews by machinawhite on Monday February 06, 2023 @04:17AM (#34675165)
"Separation of concerns" as in splitting a simple thing into 12 files because you've had too many books about architecture?
Re:Don’t Teach During Code Reviews by Dudeman112 on Monday February 06, 2023 @06:12AM (#34675890)
As in not making a 10k lines function that does everything because you didn't read any books about architecture

I get it, you've been burned out by Enterprise(tm) code. Going to the very edge of the other side isn't any better

Re:Don’t Teach During Code Reviews by machinawhite on Tuesday February 07, 2023 @02:16PM (#34697714)
A 10k loc function is just a program wrapped in a function. I find it somewhat fun to refactor those. And you're god damn right I cannot deal with this eldritch horror you architecture astronauts come up with anymore, I'll take the dumb code please :-) YAGNI + KISS >>>>> SOLID all day every day
Re:Don’t Teach During Code Reviews by Dudeman112 on Friday February 10, 2023 @05:47AM (#34738032)
>I find it somewhat fun to refactor those

I don't. I like to feel productive instead of having to do laundry before getting to the actual work because someone just went ahead without any regard for quality control

>YAGNI + KISS > SOLID

Agreed

Monster architectures are monster architectures, and yet going from Enterprise(tm) architecture to chaos architecture so you can't know anything about the system without carefully going over hundreds of lines of code isn't any better

Re:Don’t Teach During Code Reviews by Zagill on Sunday February 05, 2023 @05:37PM (#34670471)
I've always had a pretty positive attitude towards code reviews (still a junior dev), because I know there's probably something I missed or a technique I'm not familiar with or some language quirk I didn't know about. If I submit a PR with a bunch of new functionality, I'm going to be way more concerned if I don't get a handful of comments on it than if I do.
Re:Don’t Teach During Code Reviews by alwaysbeconsing on Sunday February 05, 2023 @05:47PM (#34670569)
Frankly I think everyone should have this attitude, seniors as well. (I try to) I am experienced but I know I write bugs and code that may be not as clear as it could be. We all do: we're only human.

Also depending on the codebase (and language to some degree), if someone senior writes a lot of overcomplex or abstract code that the rest of the team can't understand/maintain, that's just as much a problem as anything else.

Re:Don’t Teach During Code Reviews by jvans on Sunday February 05, 2023 @06:05PM (#34670764)
> if someone senior writes a lot of overcomplex or abstract code

For me this is a much bigger concern than subtle changes to method names. My biggest headache digging into new codebases is when I run into layers and layers of abstraction that save 3 lines of code but force me to construct an entire mental map of the codebase before I can understand how anything works.

Any tips for giving feedback to senior people here? A lot of the complexity from abstraction is very hard to quantify and experienced people can have arguments that sound reasonable.

Re:Don’t Teach During Code Reviews by moomoo11 on Sunday February 05, 2023 @06:11PM (#34670834)
Is the abstraction so that they can easily swap out pieces of the system without a single headache, or write effective tests, or to make it easy to operate in a soup of services? Because then it makes complete sense.

Like dependency injection is something that a lot of juniors struggle to understand. Or in larger applications DDD and all the crap that goes along with it.

Re:Don’t Teach During Code Reviews by jvans on Sunday February 05, 2023 @06:49PM (#34671196)
There's a long list of things that I think are abused in an effort to save on some vaguely defined future cost that never seems to materialize. Some things off the top of my head:

* Interfaces(particularly in java) that have 1 implementation.

* Interfaces with many implementations but where each implementation is used in exactly 1 place.

* large inheritance hierarchies with generic type parameters. I'm sure there's a good use case for this but it's usually a pain.

* Writing "generic" code in an effort to make something re-usable when in reality the code has knowledge of every location it is used in and tightly couples all implementations

Re:Don’t Teach During Code Reviews by cwilkes on Sunday February 05, 2023 @10:31PM (#34672967)
I actually like the “one interface with one implementation” as it makes for less surprises.

With an interface I know that only that method can be called. If a class is passed in i have no idea what methods going to be used. It also gives me a better feeling that the coder has in mind what they need a parameter to do without worrying that they are going to rely on a couple of othogonal methods to be called.

Re:Don’t Teach During Code Reviews by Zanfa on Monday February 06, 2023 @02:37AM (#34674459)
The "death by a thousand abstractions" problem must be one of the most difficult ones to solve. Each abstraction in isolation makes sense and looks like an improvement, but given a few years, the overall code becomes an inscrutable mess of layers upon layers of complexity, hiding away what it actually does.
Re:Don’t Teach During Code Reviews by simplotek on Sunday February 05, 2023 @06:44PM (#34671135)
> Any tips for giving feedback to senior people here? A lot of the complexity from abstraction is very hard to quantify and experienced people can have arguments that sound reasonable.

Perhaps a starting point for this discussion is to point out that the DRY principle is nice and all, but there is also WET. Premature abstractions are bad code, a liability and hinder development. It's always better to have two independent but mostly similar codepaths than a strategy pattern with two concrete implementations. If it's cleaner to copy/paste a method and do some tweaks, do that instead. It's not like you can't refactor it when additional use cases emerge, and if they don't emerge then the abstraction wasn't needed to begin with.

Plenty of people believe that being senior is being clever with complex stuff. It isn't. Being senior is to know you don't need complex stuff, and be able to keep as simple as possible. Abstractions go against that.

Re:Don’t Teach During Code Reviews by konfusinomicon on Sunday February 05, 2023 @07:44PM (#34671711)
the rule of three comes to mind. cleverness is confusion
Re:Don’t Teach During Code Reviews by Aeolun on Sunday February 05, 2023 @08:03PM (#34671866)
Huh, I have the opposite experience. Any time I push for a little bit more abstraction a lot of people have good arguments for why not.
Re:Don’t Teach During Code Reviews by willio58 on Sunday February 05, 2023 @07:02PM (#34671324)
As a more senior dev who reviews junior prs all the time I hope they have the same view. I work with a lot of great people who seem to always want to get better, so I think they do. I only wish I had the same level of scrutiny when I was a junior!
Re:Don’t Teach During Code Reviews by rerdavies on Sunday February 05, 2023 @06:31PM (#34671016)
I most recently worked on a 100% code-review team. Fabulous!

In my personal experience, the hump from wide-eyed novice junior to productive contributing member really doesn't take that long when every line that everyone writes is code-reviewed. The first couple of code reviews might take longer than usual. But it definitely much less time than it used to take to bring a junior up to speed. No net productivity in the first year used to be a rule, when bringing juniors onboard in the dark ages of computing. With 100% code reviews, that process seems to take no more than a couple of months -- maybe even as little as one month. The difference is dramatic.

It's a fabulous way to transmit not only good culture, but also love of our craft.

Re:Don’t Teach During Code Reviews by mplanchard on Sunday February 05, 2023 @07:34PM (#34671619)
What do you mean by 100% code review?
Re:Don’t Teach During Code Reviews by bdangubic on Sunday February 05, 2023 @07:41PM (#34671680)
Every line of code must be code reviewed before it goes to stage/prod
Re:Don’t Teach During Code Reviews by xxpor on Sunday February 05, 2023 @08:00PM (#34671838)
… how else do people operate? Complete yolo?
Re:Don’t Teach During Code Reviews by Aeolun on Sunday February 05, 2023 @08:06PM (#34671896)
Maybe rubber stamp PR? We can say we review everything 100%, but practically this sometimes just means clicking the approve button.
Re:Don’t Teach During Code Reviews by rerdavies on Sunday February 05, 2023 @09:13PM (#34672394)
lol. I've been doing this for a long time. It wasn't always done that way.
Re:Don’t Teach During Code Reviews by ornornor on Monday February 06, 2023 @02:21AM (#34674345)
You’d be surprised how many places operate that way. Or better, commit to master via the web ui because “it’s a quick small fix”
Re:Don’t Teach During Code Reviews by nonethewiser on Sunday February 05, 2023 @07:11PM (#34671424)
This sounds like you and your peers don't really read and take the time to understand what changes are in the PR.
Re:Don’t Teach During Code Reviews by cramjabsyn on Sunday February 05, 2023 @07:48PM (#34671741)
> I think people take code reviews way too personally. Like, my priority is to ensure I don’t have headaches down the line

I feel this, and have personally experienced submitters taking feedback far too personally, to the point of even using sunken cost as justification of their design, completely overlooking valid points of feedback.

I’m looking for basics. Will it work? is the code clear? is it commented/documented? is the approach simple and maintainable?

Some submitters really need coaching on how to receive feedback, and how to plan their timelines to incorporate revisions.

Re:Don’t Teach During Code Reviews by Aeolun on Sunday February 05, 2023 @07:59PM (#34671834)
To be fair, some people are just pedantic. Just because you are the reviewer doesn’t mean things have to be done exactly the way you say.

If I never accept anything from more junior people because it isn’t perfect, how are they ever going to stay motivated?

I aim for one or at most two rounds of review, because anything else is just depressing.

Re:Don’t Teach During Code Reviews by cramjabsyn on Sunday February 05, 2023 @09:40PM (#34672608)
Ehhh far from perfection, more like “please use the native feature that handles this in 2 LOC instead of shelling out to an external 100 line script”
Re:Don’t Teach During Code Reviews by Aeolun on Monday February 06, 2023 @10:24PM (#34688341)
There’s limits and degrees to anything. I guess I never get PR’s that are quite that boneheaded.
Re:Don’t Teach During Code Reviews by interactivecode on Monday February 06, 2023 @03:20AM (#34674701)
100% agree, code review should be there to check if the code doesn’t contain any obvious security risks or mistakes.

Designing features, architecture and learning should happen before someone even gets to the point of submitting a PR. Plus if it can be improved on in follow PRs then do that instead of blocking juniors with pedantics

Re:Don’t Teach During Code Reviews by pjmorris on Sunday February 05, 2023 @08:46PM (#34672190)
Jerry Weinberg pitched the concept of 'egoless programming' [0] with the suggestion that it is possible to not take reviews of your code personally, with examples from his experience. Weinberg is careful to address the problem of feeling attacked by working on the social environment to avoid or limit attacks and the consequent defenses.

Thirty years later, egoless programming is one of Robert Glass's favorite fallacies in 'Facts and Fallacies of Software Engineering.'

IOW, it is a hard problem!

The SE research community has been looking into this for awhile (e.g. Greiler, Bacchelli)

[0] 'The Psychology of Computer Programming' (1971), Gerald Weinberg

[1] 'Facts and Fallacies of Software Engineering', Robert L. Glass

Re:Don’t Teach During Code Reviews by rendaw on Sunday February 05, 2023 @11:59PM (#34673533)
Unless the submitter is stuck or asks for it, I avoid giving recommended changes on code reviews and instead just explain what (bad) consequences pieces of code have.

Providing recommendations takes away autonomy from the person who wants to contribute, and it's easy to end up glossing over the real consequences and ending up with "well, I would have done it this way" nit picking reviews.