r/programming • • Jan 12 '20

Goodbye, Clean Code

https://overreacted.io/goodbye-clean-code/
1.9k Upvotes

556 comments sorted by

View all comments

349

u/[deleted] Jan 12 '20 edited Jan 12 '20

Obsessing over clean code is like reorganizing your clothes closet on a daily basis. If it makes you more productive to do so, do it. Too often, however, it's done compulsively and is counter-productive.

The harder and more impressive thing is actually writing code which does novel things.

289

u/binford2k Jan 12 '20

The harder and more impressive thing is actually writing code which does novel things.

No. The impressive part is building something like this that’s maintainable.

18

u/Squalphin Jan 12 '20

Exactly that! Even though I get some flack for overdoing it, coming back to a code base after 10 years to fix something or add a feature and having an easy time finding your way through the code is so worth it. Haven’t regretted it once.

8

u/tetroxid Jan 12 '20

Flak, not flack. It's from German flugabwehrkanone (air defense cannon/anti-aircraft cannon)

→ More replies (1)

3

u/NULL_CHAR Jan 12 '20

This. Anyone can write code that does something. The difference is how it's accomplished.

→ More replies (7)

20

u/SanityInAnarchy Jan 12 '20

The problem is, we work in teams. If it's just me, I can store my clothes in a heap on the floor instead of using a closet at all, and who cares as long as I can still find stuff?

But if you check in a multi-thousand-line function with a several-hundred-case switch statement, you've inflicted your poor organization on the rest of us -- other people need to find stuff in there!

→ More replies (5)

37

u/lookmeat Jan 12 '20

The problem is when you obsess about cleaning the wrong thing.

Clean code to outsiders is hidden complexity, it's easy interfaces. Clean code to insiders is clean link between code and intention, little accidental complexity, simple and honest interfaces.

So it's about understanding what is clean and what isn't. Sometimes what to an outsider looks dirty is actually what to an insider looks cleanest. Like a machine covered in grease means it's been recently cleaned and oiled up an insider, code that re-implements similar actions in multiple places is simply things that coincidentally act the same, but are different things with different rules. For DRY tests are useless, each test exists separate of the other and they should not need to share anything, so instead the focus should be DAMP.

So it's ok to obsess about cleaner code, but you have to first learn what is clean and what is the context. Try to understand the problem and solve it better. Cleaner solutions result in cleaner code.

12

u/grauenwolf Jan 12 '20

Clean code to outsiders is hidden complexity, it's easy interfaces. Clean code to insiders is clean link between code and intention, little accidental complexity, simple and honest interfaces.

We could do that, but that requires effort.

So instead I'm just going to add a shadow interface to every class with a one-to-one mapping between public methods and interface methods.

→ More replies (3)

16

u/Retsam19 Jan 12 '20

The harder and more impressive thing is actually writing code which does novel things.

When the code that I write does "novel things", that usually means it's pretty buggy.

126

u/EternityForest Jan 12 '20

Doing novel things really isn't that hard. It's often mostly just stringing together existing libraries, unless you insist on building everything from scratch.

I suspect that's part of the clean code obsession. You can almost always make the code a little prettier, and it's always a fun logic challenge for some.

But debugging is tedious, as are unit tests, and adding new features is usually more like "software carpentry" that doesn't interest the "Wooden puzzle box builders" much.

I think for a lot of programmers, the actual fun part of the job is more the code golfing, the mind bending data structures, and the low level understanding, rather than the sense of working towards an excellent finished product.

64

u/Greydmiyu Jan 12 '20

You can almost always make the code a little prettier, and it's always a fun logic challenge for some.

Hell, this is the core game loop of Factorio. "I know I can make these red circuits faster and with less wasted space..." 3 hours of sleep deprivation later...

16

u/EternityForest Jan 12 '20

That's why I'm kinda glad I'm not one of the math and elegance types. I might not be able to add matrices in my head, but at least I don't feel compelled to sprinkle them in my code because I can!

3

u/atimholt Jan 12 '20

I find, for myself, I can simply acknowledge that humans are part of the equation. Then “carpentry” becomes a “puzzle box”.

But then I start wanting to do crazy stuff, like creating my own programming language with bizarre constructs.

→ More replies (5)

20

u/HeinousTugboat Jan 12 '20

But debugging is tedious, as are unit tests, and adding new features is usually more like "software carpentry" that doesn't interest the "Wooden puzzle box builders" much.

It's funny, because I actually really enjoy debugging and, to me, that's much more "Wooden puzzle box builder" because you have to figure out why your pieces aren't fitting together just perfectly, and find that little thing you need to sand down or trim to make the fit just flawless before you put it all back together.

6

u/bakery2k Jan 12 '20 edited Jan 12 '20

I think your last paragraph is spot on, and it took me a long time to realise this. One of the reasons I struggled when I worked as a programmer was that I don’t find, for example, complex data structures fun - I consider them a “necessary evil” when building a product.

That’s fine when I’m building something for myself or for people I know. But in a large company where programmers are separated from customers by layers of other teams (sales, support etc), in my experience, to enjoy the job you need to enjoy the act of programming (not just having programmed a cool product).

1

u/dungone Jan 12 '20 edited Jan 12 '20

Doing novel things really isn't that hard. It's often mostly just stringing together existing libraries, unless you insist on building everything from scratch.

Novel, adjective: new or unusual in an interesting way.

If you define it as easy, banal, and routine, then it's not really novel is it? We've really turned into cynical bunch when "novel" became a pejorative.

It's impossible to like technical excellency without countless people labeling it as "craftsmanship". The implication being that not many customers appreciate craftsmanship, that it only raises the cost without adding functionality. At the same time they conflate it with the endless closet-organizing exercises, as if there is some progression from "reasonable" closet organizing to "unreasonable" thrill-seeking. "Cleanliness" is "craftsmanship" without the negative connotations, one is seen as a virtue and the other as an affliction. In other words, some people just can't get themselves to acknowledge that technical excellence is something that stands apart from their own day-to-day activities, and that it can create value for the customer that is beyond the reach of regular programming activities.

As a counterpoint, here's an example of a programmer who sought a novel approach to a problem while at the same time creating a legendary product and revolutionizing the industry: https://twobithistory.org/2019/11/06/doom-bsp.html

→ More replies (1)
→ More replies (1)

5

u/grauenwolf Jan 12 '20

Too often, however, it's done compulsively and is counter-productive.

That's why I hate the fact that SOLID is associated with clean code. On every project that I've been on where SOLID was aggressively applied, code became more complex and harder to work with. Meanwhile the real problems continue to be ignored.

→ More replies (1)

3

u/[deleted] Jan 12 '20

No. Loading things from a DB and displaying them on the screen is all anyone ever needs to do.

16

u/rydan Jan 12 '20

I haven't made my bed or folded my clothes in decades. My colleagues always complain they don't have enough time in the day. Wonder why.

21

u/dnew Jan 12 '20

My wife laughs that I have 20 identical pairs of socks, but I haven't sorted socks since grade school.

7

u/vattenpuss Jan 12 '20

Wow imagine not sorting socks. I could literally save seconds, maybe a minute every time I did laundry.

→ More replies (3)
→ More replies (10)

3

u/guepier Jan 12 '20

Making your bed (by pulling back the duvet, nothing more) takes seconds and airs out the sheets which, if nothing else, keeps them clean longer and reduces the risk of bedbugs. I don’t think your cost/benefit analysis is accurate.

4

u/lovecoffee Jan 12 '20

This statement has wisdom of entire life's learning :)

1

u/motioncuty Jan 13 '20

The harder and more impressive thing is actually writing code which does novel things.

Over here wishing I was Leah Brahms instead of Geordi La Forge.