Live data from Hacker News

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

qntm.org

91–100 of 216 posts

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

#91

Earlier quoted context omitted.

That’s my understanding as well, quality for the sake of it isn’t appealing. But it is known that a quality foundation enables everything in the business, reduces waste, churn, and increases profits. Yet when it comes down to actually doing it, nobody cares. Fast and cheap always wins over quality. That’s not necessarily a problem overall, but it is for me because I derive no satisfaction from shipping low quality co…

Think of it this way. Imagine you hire an electrician to do some task. If while he's there he cleans up some stuff around where he was working, that's welcome. If he starts rewiring your whole house for no particular reason, even though everything was working fine, and billing you by the hour, you might not be pleased.

Absolutely but this isn’t the situation I’m talking about here.

To reuse your analogy, I’m talking about a restaurant who has a mess of an installation, several panels and breakers, not all up to code, and the electricity frequently shuts off taking hours to figure what happened and how to restore it. It’s also a mild fire hazard and there have been a few close calls that could have burned the place down.

The son in law, a hobbyist electrician, did the installation and extended it for free while the business was starting up and growing. He didn’t do it right but it works and got the restaurant so far.

Now the restaurant is very popular but the constant blackouts are driving people away and hurting profits. The mild fire hazard and not following code irks the authorities and insurance companies and they’re threatening closure. It needs an extra stove to keep up with customer demand but no one can figure out how to hook one up to the existing rats nest, let alone do it safely.

The owner knows this is a problem and is looking for a proper electrician to fix the mess.

In real life, I’d expect the business owner to agree with the electrician on a plan so that either the retaurant stays open (maybe at a lower capacity) so that the tidying up can happen gradually, or close down for renovations for a while so the whole thing can be overhauled quicker.

But what happens in our industry and in my experience is that instead the restuarant owner asks the electrician to tighten a screw or two here and there so that this power socket isn’t as wobbly anymore but then demands even more additions to the janky system and demands they be done as fast and cheap as possible as this is now the top and only priority.

Nothing really improves but the owner (at least for a while) can hide it from the authorities and insurance company because he has a quote and a specialist working on the system. Then the owner can blame the electrician because “he wasn’t able to balance fixing up the installation while extending it, so we’ll fire him and look for someone actually good this time”. Rinse and repeat ad nauseam.

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

#92

Clean Code was one of the first books I read as a History student trying to become a self taught developer. From my point of view, coming from the rigor of historiography, the book was inconsistent and dogmatic. Still I took it as a replacement to talking with an experienced engineer, because that’s how it felt and most of the principles were fine when not taken to the extreme. But now in my career I’ve seen awfully…

I always recommend "The Pragmatic Programmer" (Hunt, Thomas) and "Code Complete" (McConnell).

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

#93
post #77

Earlier quoted context omitted.

It can definitely be confusing to hear "clean" when communicating in a professional setting. That said, in the book he covers correctness and understandability in nearly every paragraph. It's all the book is about really. It's called "clean" because it's concise and a catchy book title.

If you say the book “covers correctness and understandability in nearly every paragraph” then I’m convinced we must be talking about different books. For example, the book presents a rule for class names: > Classes and objects should have noun or noun phrase names like Customer, WikiPage, Account, and AddressParser. Avoid words like Manager, Processor, Data, or Info in the name of a class. A class name should not be…

Let’s say my site has a download image feature that embeds per-user digital licenses into downloaded images at download time. This might take some processing so there is a queue and an abstraction representing the downloaded file. There are also several endpoints serving different types of image files.

What shall I call the unit of code orchestrating these download processes, if not ImageDownloadManager?

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

#94

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.

You stand up and talk about it publicly.

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

#95
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.

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

#96

Earlier quoted context omitted.

If you say the book “covers correctness and understandability in nearly every paragraph” then I’m convinced we must be talking about different books. For example, the book presents a rule for class names: > Classes and objects should have noun or noun phrase names like Customer, WikiPage, Account, and AddressParser. Avoid words like Manager, Processor, Data, or Info in the name of a class. A class name should not be…

Let’s say my site has a download image feature that embeds per-user digital licenses into downloaded images at download time. This might take some processing so there is a queue and an abstraction representing the downloaded file. There are also several endpoints serving different types of image files. What shall I call the unit of code orchestrating these download processes, if not ImageDownloadManager?

ImageDownloadPreparer?

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

#97

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…

> code should be correct and easy to understand. I think “correct and easy to understand” is a much more useful rubric than “clean”. Obviously it’s still subjective. Code that is easy to understand for you may be hard for me to understand.

There's a deeper problem here that has driven a lot of disputes over the years.

"Ease of understanding" is not a stable property of code. If you have two separate pieces of code that are easy to understand, and the only thing you do with them is combine them, your resulting one piece of code may also be easy to understand.

Or it might be next to impossible to understand.

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

#98

Earlier quoted context omitted.

I'm still amused by claims that the book is dogmatic when these paragraphs are in the opening chapter: > Consider this book a description of the Object Mentor School of Clean Code. The techniques and teachings within are the way that we practice our art. We are willing to claim that if you follow these teachings, you will enjoy the benefits that we have enjoyed, and you will learn to write code that is clean and prof…

The claim is not that the book is dogmatic, but that its worshippers (for lack of a better word) are. The infamous Design Patterns book, despite having a similar "disclaimer", has had a similar effect.

[deleted]

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

#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 and for that matter structs is that as requirements evolve, inevitably you will need to extend the code base and at some point `is_admin` alone won't cut it, you'll need an is_moderator etc.

This leads to two things, one is function signature pollution and unnecessary extra validation code, eg. what happens if both is_admin and is_moderator are set?

What about the functions relying on the old signature? Perhaps you make separate versions of the functions, eg. create_admin_user and create_moderator_user and keep the old one with the flag, then you can keep backward compatibility...but at the cost of an api that makes people go insane when using it.

More likely you'd then go to an enum which leads backward incompatible changes, and likely a refactor, which in the event of a library can break dependent code and in all cases is a lot more work than just using an enum in the first place.

Try to write code for the future reader and writer of the codebase. An enum will allow readers to immediately understand that there is a [normal, admin] distinction and adding a moderator would be as simple as adding a [normal, moderator, admin] in there.

Then, assuming you've written your code in a proper manner, your IDE will tell you all the places where a moderator needs to be accounted for in the code base.

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

#100

A common theme not only in software but other industries: Beware of people selling you advice. They are the ones who will breed dogmatic illogical cargo-cults of people whose only rebuttal when questioned is some variant of "because someone who sold me this book that claims it'll make my code better said so", and that can't be a good thing in general. but we assume that Martin doesn't literally mean that every functi…

Ye flat functions are way underrated. It is so hard to keep track of the call stack when reading code for me. Deeply nested code is read only, unless the problem is nicely modelled as recursive in some way.

And what kind of problem is nicely modelled as recursive?

It’s when your data items have children, which can have children, which can have children...

Post reply on HN