Live data from Hacker News

It's probably time to stop recommending Clean Code (2020)

qntm.org

101–110 of 216 posts

Re: It's probably time to stop recommending Clean Code (2020)

#101

Earlier quoted context omitted.

> They all say they do of course, while actually being afraid of doing this because it takes more time and money. That is my experience too with most places - they say that they support clean, well tested and maintainable code and then turn around and ask things to be delivered in unreasonable time resulting in quick and dirty code. > I also suspect that not focusing on clean code is a strategy many managers have bec…

So… how do you deal with this on a personal level? How do you retain any shred of sanity or enjoyment from your work? I can’t stand self inflicted toil and the stress from constant firefighting which is invariably the result of these short term policies. It makes me want to quit programming altogether and work in something totally unrelated even though I love programming. Just not the way employers want it.

One option is to work for a company where an important part of the product they make is code itself, e.g. an SDK. Another is to switch to a programming language that tends to attract quality-minded people, e.g Rust, Go, Haskell.

Re: It's probably time to stop recommending Clean Code (2020)

#102

Earlier quoted context omitted.

So… how do you deal with this on a personal level? How do you retain any shred of sanity or enjoyment from your work? I can’t stand self inflicted toil and the stress from constant firefighting which is invariably the result of these short term policies. It makes me want to quit programming altogether and work in something totally unrelated even though I love programming. Just not the way employers want it.

You stand up and talk about it publicly.

Who listens, though? Look at seminal work like “the mythical man month”… while most people “in the trenches” agree that nine women can’t make a baby in one month, project managers and executives still very much think it’s possible 40 years later.

Re: It's probably time to stop recommending Clean Code (2020)

#103
post #99

My experience is that I run into a lot of relatively junior programmers who are concerned about clean code. Is my code clean? How do I organize my code? How do I make it clean? Should we clean up this code? I almost never want to use the word “clean” when I’m talking about code. These days, when someone asks me to review code, and they start talking about “clean” code, I shift the discussion to two points—code should…

> Like, “you shouldn’t use boolean flags as parameters, you should use enums” becomes “I can‘t understand the meaning of true/false at the call site, so let’s use an enum instead”. That's not the reason to use enums instead of parameters for functions, rarely will you not be able to understand what the bool arg means in: create_user(..., is_admin: bool) If you don't then you need a better IDE. The reason to use enums…

At the call site, unless it's a keyword argument, you don't know what the parameter is named.

IDEs help with this of course, but it's not just the "2 options becomes 3 options" situation that recommends against them

Re: It's probably time to stop recommending Clean Code (2020)

#104

From my decade writing software professionally and my current job search, I really question the actual demand for clean code. That’s unfortunate because it’s my specialty and what gives me job satisfaction. I love fixing things. I actually enjoy working on a crappy codebase that has made the company money but is now too hard to maintain/extend and needs cleaning. Adding tests, refactoring, extracting functionality to…

> I love fixing things. I actually enjoy working on a crappy codebase that has made the company money but is now too hard to maintain/extend and needs cleaning. Adding tests, refactoring, extracting functionality to discrete functions, figuring out what the black box actually does, etc. This is what I’ve specialized in.

I am thankful that people like you exist, but after having taken on that role out of necessity myself, I've mostly been left disliking the experience.

Working withing under-documented and under-tested "legacy" codebases, especially the kind where the developers got clever with design patterns, both putting them in when they make sense as well as when they didn't. Those codebases are hard to navigate and hard to refactor (outside of fully automatic renaming/extracting interfaces etc.) and even harder to change - in many cases because you're not even aware of the design assumptions or aspects of the architecture that were made by someone who is now long gone.

For example, I worked on a system where users could submit corrections to data and those could either be accepted or removed. There was a CorrectionFormService, that also was related to CorrectionEntryService, but both of those were abstract and had corresponding CorrectionFooFormService and CorrectionFooEntryService instances, as well as an additional CorrectionFooService. In the database, there also were foos and foos_corrections tables, the latter of which was related to correction_forms, sometimes with additional related tables. The problem was that the logic didn't actually fit such neat structure, so depending on whether you're working with Foo, Bar or Baz, more and more of the methods had to be overriden, as well as new ones added, none of which was actually documented. In most cases you were supposed to have the original_id column point at the foos (or whatever) table id that had the actual data, except when for some reason original_id was the same as id and instead you had something like object_id store that information. And on top of that, there were database views which were used for querying the data, where there were additional rules for the id, original_id and object_id column values, with about 10 prior Jira/Redmine issues related to how this data should work. Not only that, but there were also requirements for accepting some of the data recursively (since parent_id was needed for some of the data structures), but not in all of the cases, only when some other enum column had a particular value in a related table.

Long story short, the more you looked into it, the more details spilled out, to the point where you could not keep a full mental picture of it in mind. Some of the implementation was okay, some of it was ridden with iteration overhead and accidental complexity. Contrast getting to write new code and getting things done in hours, versus spending days if not weeks (across multiple developers, actually) working to get things done within this pre-existing setup. Maintenance work will typically take longer than developing new features and, in my personal experience, will be more mentally draining.

Re: It's probably time to stop recommending Clean Code (2020)

#105
post #87

I get the impression that Uncle Bob Martin worked on CRUD-type projects with very few interesting design decisions to be made about what the software should do computationally. In these projects, the programmer's mind wanders. It latches onto the endless design decisions one can dream up about how the source code should be organized. It's hard to imagine anyone going this far down the rabbit hole of strange code orga…

> CRUD-type projects with very few interesting design decisions to be made about what the software should do computationally. Isn’t this by far the bulk of code businesses produce and need though? Very few businesses actually have the scale or product that requires more than a glorified CRUD with arcane business rules slapped on top.

Actually it can get really complex really fast if the business rules happen to apply to migrations and operations on heavily relational data, especially with composite keys involving date ranges.

Re: It's probably time to stop recommending Clean Code (2020)

#106
post #45
post #44

Haven't read but it's definitely time to start demanding people write clean code. My house often gets messy, and so does my code. And then I clean my house and refactor my code. I try to steer away from refactoring for the sake of making my code look sexy, which it does, but putting time on the calendar for an almost guaranteed need to shuffle things around when you get a chance feels good and makes your future self…

The issue is that the meaning of "clean code" here isn't code that's clean and legible. It's code written in the typically over engineered OOP-heavy Java style. Think lots of "patterns", massive amounts of inheritance, interfaces and factories everywhere. I made the decision of abandoning any clean-code-ish practices within my teams long ago. I still demand the code to be structured sensibly, be clear, well named and…

"clean" means more formal and specific?? That's often the opposite of clean. But ok understood. I should have read the article.

Let's not add LOC if it's not helpful. I finally picked up Typescript to strengthen my Javascript code, and I'm a huge fan now, but a lot of the added features aren't always helpful whether because of project size or complexity. And the typeahead -> add code features on IDEs add a lot of bloat like yeah interfaces on _everything_.

Re: It's probably time to stop recommending Clean Code (2020)

#107
post #99

Earlier quoted context omitted.

> Like, “you shouldn’t use boolean flags as parameters, you should use enums” becomes “I can‘t understand the meaning of true/false at the call site, so let’s use an enum instead”. That's not the reason to use enums instead of parameters for functions, rarely will you not be able to understand what the bool arg means in: create_user(..., is_admin: bool) If you don't then you need a better IDE. The reason to use enums…

At the call site, unless it's a keyword argument, you don't know what the parameter is named. IDEs help with this of course, but it's not just the "2 options becomes 3 options" situation that recommends against them

That's not a problem with bool arguments, that's a problem with the language and tooling.

Re: It's probably time to stop recommending Clean Code (2020)

#108

My experience is that I run into a lot of relatively junior programmers who are concerned about clean code. Is my code clean? How do I organize my code? How do I make it clean? Should we clean up this code? I almost never want to use the word “clean” when I’m talking about code. These days, when someone asks me to review code, and they start talking about “clean” code, I shift the discussion to two points—code should…

> Obviously it’s still subjective. Code that is easy to understand for you may be hard for me to understand.

there is nothing obvious about this, I think it's very objective what unreadable means (mostly it's complicated without a reason)

Re: It's probably time to stop recommending Clean Code (2020)

#109
post #64

Earlier quoted context omitted.

I think as professionals many of us like to take pride in our work. A natural way to do that is for code to be "clean". The problem, as I see it, is that this is often a subjective metric and what we take pride in doesn't always align with what delivers tangible value to an organization (a point you alluded to). Clean code can bring tangible value, but big rewrites taken on for that goal can often not. I personally t…

> what is valuable depends a lot on context and the point in life of a particular project+team+organization. For sure, and I only target companies or teams that are mature, struggle to move forward because code quality grinds things down to a halt, and that express the desire for improvement there. However, there are very few companies that 1. Even have the awareness to realize this is where they’re at, and 2. Actual…

Any organisation with messy code doesn’t care about clean code - sure, they may regret it, they may wish it would magically go away, but if they cared then they wouldn’t have allowed all the dirty code to pile up. The only organisation in which your work will be valued is one in which the code is already clean.

Re: It's probably time to stop recommending Clean Code (2020)

#110

Earlier quoted context omitted.

> CRUD-type projects with very few interesting design decisions to be made about what the software should do computationally. Isn’t this by far the bulk of code businesses produce and need though? Very few businesses actually have the scale or product that requires more than a glorified CRUD with arcane business rules slapped on top.

Actually it can get really complex really fast if the business rules happen to apply to migrations and operations on heavily relational data, especially with composite keys involving date ranges.

Then the advice in clean code and other similar books apply.

Parent comment implied the book isn’t relevant because it only applies to CRUD apps and I argue that they’re the vast majority of code produced so while the book isn’t relevant to 100% of codebases, it is useful advice in the majority of cases nevertheless.

Edge cases are gonna be edgecases and will require tailored advice.

Post reply on HN