Live data from Hacker News

Goodbye, Clean Code (2020)

overreacted.io

141–150 of 224 posts

Re: Goodbye, Clean Code (2020)

#141

Duplicated code != Messy code. The only time duplicated code is bad is when there is an actual logical requirement for the multiple instances of duplicated code to be the same. Like some actually underlying concept linking the duplicated code sections that is worth abstracting. That is not always the case. Just as often IME the situation is actually, "these two things happen to have the exact same behaviour right now…

>> If the reason for the duplicated code is just coincidence,

Totally agree! However, if code is duplicated because there is some is some assumption of functionality that is represented in multiple places then it gets more iffy. I took this article to imply that in each function implementation there were something like similar calls to a library or particular orders of redrawing based on the way the code base worked. That's where it can get dangerous.

It's not as dangerous if there are four very similar functions sitting right next to each other. But if there is a block of code that implements a way of working and another block of code has the same implementation in a place that isn't as easy to find that seems dangerous to me. If you want to make one change to a code base ideally you make the change in one place.

Re: Goodbye, Clean Code (2020)

#143
Here the author tries something then gives up. That does not mean clean code is not something to aspire or pursue.

What is described as building trust can be also interpreted as groupthink and colleagues forming pacts of mutual non-criticism (which breeds mediocrity). Which is also the way to build dogmatic cults of personality, and becoming superficial developers that care more about talking about their weekend than their craft.

You do not trust code. Memory and attention are fragile. Everyone makes mistakes. Everyone can have a bad day, be distracted, tired, etc. Building trust sucks. Trust nothing and be able to verify everything.

Your job is to edit code: add, delete, modify code. Each time you check in code it becomes company property. It is not "your" code. Modifying other people's code is completely OK, and expected.

In the end, this article is just wrong. "Give up, tech debt is your friend. Your job is to be best friends forever with your colleagues". All wrong conclusions.

Re: Goodbye, Clean Code (2020)

#144
post #128

I'm shocked that from all discussion nobody noted the root of all evil: "It was already late at night (I got carried away). I checked in my refactoring to master and went to bed, proud of how I untangled my colleague’s messy code." No PR, no code review, no CI. Just a cowboy pushing to the master..

This is just how some places work, unfortunately. We all push to main, no code reviews, no CI etc. Hell, some people here patch things by downloading the live dll, decompile, update code, recompile and stick it back to live...

You realise that everyone pushing changes to main several times a day is the definition of CI? and it's pretty much impossible to do with code review as a gate for pushing to main. Interesting how CI has become semantically diffused to mean literally the opposite of CI: tooling and processes that delay integration and make it easier to work in isolation.

https://wiki.c2.com/?ContinuousIntegration " The most granular unit of integration should be one step of one refactor. "

Re: Goodbye, Clean Code (2020)

#145

Duplicated code != Messy code. The only time duplicated code is bad is when there is an actual logical requirement for the multiple instances of duplicated code to be the same. Like some actually underlying concept linking the duplicated code sections that is worth abstracting. That is not always the case. Just as often IME the situation is actually, "these two things happen to have the exact same behaviour right now…

I don't think this is necessarily true. If I have one place in my code where I sign unsubscribe tokens for emails and another place where I sign cookies for auth I don't want to implement a HMAC twice. Even if the verification paths are different so the algorithm doesn't actually need to be the same it is still better to use the same code for both so that any bugs, inefficiencies or other problems can be fixed once rather than up to twice.

I think the true decision function lies somewhere in the middle. For relatively simple code that doesn't need to be in sync then yes, duplication is likely the best option. For complex code or code that should stay in sync then extracting the common code is likely best. But there is a huge range of code in the middle where it is a judgement call with no obviously correct answer.

Re: Goodbye, Clean Code (2020)

#146
post #48

When we don’t feel confident in our code, it is tempting to attach our sense of self-worth and professional pride to something that can be measured. I don't think assuming people who disagree with you lack confidence and are "compensating" is an effective way to reach an audience. Rewriting your teammate’s code There should be no such thing as "your teammates code", there is only your team's code. If the changes were…

You might be projecting. That read like the authors personal experience, one that you might reasonably suspect others have shared.

Re: Goodbye, Clean Code (2020)

#147
The real story here is not about the code.

When it's your own personal project and you can be your own little tyrant, do whatever you want. Be as "clean" as you need to be. But this was at work, and Dan was being a bad coworker.

He snuck in a change in the middle of the night over a coworker's code. This code wasn't his responsibility. He didn't leave his thoughts on a PR where others could discuss it. He overwrote someone else's code without asking. There was no opportunity for discussion or collaboration. Dan's actions said he's right and his coworker is wrong. They said he doesn't trust his coworkers. They said he knows best. They said if you want something done right around here you have to do it yourself. Dan was not being a team player. This story is less about code and more about team dynamics.

I hope Dan knows this and he was just trying to sneak the message past people who don't take social cues as easily as others. I hope his boss didn't just tell him to revert his change. I hope his boss told him why.

EDIT: I just reread the article and I think Dan missed the point. This wasn't about the code, as I said. But Dan really does seem to think it's about the code.

Re: Goodbye, Clean Code (2020)

#148
post #13

"Firstly, I didn’t talk to the person who wrote it. I rewrote the code and checked it in without their input. Even if it was an improvement (which I don’t believe anymore), this is a terrible way to go about it." While undeniably true, this feels completely orthogonal to the question of clean code. You could ruffle someone's feathers in the exact same way by taking code into the opposite direction. "Goodbye, Clean Co…

Well... you're right. But humans have a tendency to become zealots. They (we) take a good thing, and make it The One True Thing(TM). It happens with many people with many different things. It seems to just be human nature.

So it may be good to remind ourselves "Hey, this is just a thing. Use it when it makes sense, and don't overdo it."

Re: Goodbye, Clean Code (2020)

#149
post #120
post #41

Earlier quoted context omitted.

The "new way of doing things" is risky and might not turn out so good after all. If you treat the new way as an experiment, and only gradually convert the rest of the code, you're in for a smoother ride.

Please no, this is how you end up with 20 different experiments and zero consistency in everything. Gradual migrations are fine because it makes project managers happy but it requires a commitment to actually follow through with it. If there's a chance that you won't actually have dev time to finish the migration then just don't do it. It can't be that important then. It's totally fine to try out an experiment in a b…

> Please no, this is how you end up with 20 different experiments and zero consistency in everything.

This comes from a lack of discipline in the org, not from the parent's (IMO) correct guidance that an org should undertake architectural changes with pilots in isolated parts of the code base.

Re: Goodbye, Clean Code (2020)

#150
post #13

"Firstly, I didn’t talk to the person who wrote it. I rewrote the code and checked it in without their input. Even if it was an improvement (which I don’t believe anymore), this is a terrible way to go about it." While undeniably true, this feels completely orthogonal to the question of clean code. You could ruffle someone's feathers in the exact same way by taking code into the opposite direction. "Goodbye, Clean Co…

> While undeniably true, this feels completely orthogonal to the question of clean code.

I think this mentality and the Clean Code Movement (with capital Cs) actually have a lot in common.

Much of the Clean Code movement is occupied with the idea that there is one, single, right way of doing things. Anyone who does things differently is doing things the wrong way.

There is a subset of programmers who are attracted to these movements because it can feel like a free license to feel superior to your peers. Once you understand all of the rules and intricacies of the Clean Code Movement, it can feel like a free pass to push the Clean Code rules on to others and the codebase. No need for code review or consultation, because you've already decided that the Clean Code Way is the right way and therefore there isn't anything to discuss.

Post reply on HN