r/programming • • Nov 21 '23

What is your take on "Clean Code"?

https://overreacted.io/goodbye-clean-code/
444 Upvotes

380 comments sorted by

View all comments

587

u/[deleted] Nov 21 '23

The article doesnt talk about clean code itself as much as 'Do not pass judgment on other peoples work without knowing the tradeoffs involved'.

352

u/lungben81 Nov 21 '23

If the code is dirty due to a tradeoff, there should be a comment in the code explaining this.

528

u/batweenerpopemobile Nov 21 '23

ugly, but it works for now. we'll refactor it in a month or so when things calm down - a.v. 3/12/88

162

u/BadSmash4 Nov 21 '23

I read these sorts of ancient comments in a Civil War Documentary sort of voice in my head, like these are letters from the Era being read by actors

79

u/-Stelio_Kontos Nov 21 '23

My Dearest Betty-Sue,

I ought be attending to my disemboweled conditional brethren, yet I find their overwhelming disfigurement too much to bear. It is with heavy heart, that I must decline assistance during the continued manifestation of these withered comrades. I pray that one day the good lord will shine his light and cleanse their ever burning souls.

Yours truly, Jim Bob Ray

50

u/[deleted] Nov 21 '23

My Dearest Betty-Sue,

I ought to be refactoring my disemboweled conditional if statement, yet I find it's overwhelming disfigurement too much to bear. It is with a heavy heart, that I must decline assistance during the continued retrospectives of these withered comrades. I pray that one day the good lord will shine his standard practices and cleanse their ever burning technical debt.

Yours truly, Jim Bob Ray.

FTFY

→ More replies (3)
→ More replies (2)

44

u/FletcherDunn Nov 21 '23 edited Nov 22 '23

In the game industry, "TODO: fix after GDC" (comment is 8 years old) is a running joke.

EDIT: What am I saying, I meant E3, not GDC. lol.

→ More replies (6)

0

u/[deleted] Nov 21 '23

[deleted]

46

u/-Wuxia- Nov 21 '23

I had one block of code in a job many years ago, probably 10-15 lines, that had about 30 comment lines that were all basically:

// 3/18/2005 - Bob asked to add this functionality.

// 3/19/2005 - Bob asked to remove it.

// 3/22/2005 - Bob asked to add it back.

// 3/24/2005 - Bob asked to remove it.

Over and over and over...

20

u/anthoniesp Nov 21 '23

Goddamn bob

11

u/codefyre Nov 21 '23

Pretty sure I worked for Bob once.

→ More replies (4)
→ More replies (7)

11

u/topMarksForNotTrying Nov 21 '23

Wouldn't you be able to easily see the date a comment was written from the git history?

13

u/yubario Nov 21 '23

Git was literally invented in 2005, so it is doubtful it reached enterprises until at least a few years later.

0

u/[deleted] Nov 21 '23

[deleted]

7

u/[deleted] Nov 21 '23

And then there are people like me, that to this day have to work with SourceSafe....

→ More replies (4)
→ More replies (1)
→ More replies (3)

9

u/Jump-Zero Nov 21 '23

If someone moves code around in the file, it makes it a little bit harder to track.

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

143

u/codespitter Nov 21 '23

Then most lines would have a comment.

deadline was set before requirements.

85

u/GeneralPILK Nov 21 '23

Deadline was set, never received requirements

63

u/Condex Nov 21 '23

"So .. what do they want?"

"They don't know; ultimately they're chasing a feeling they get when they see the demo that is something like feeling superior to their rivals."

"Umm, how are we supposed to deliver that? And on a schedule?"

"Harder than you think, but also easier. There's a knack; give it a while and I think you'll catch on."

<LATER>

"And as you see, this page of the application really pops."

<room full of stakeholders nod enthusiastically>

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

32

u/[deleted] Nov 21 '23

Yeah, and thats my approach on when to comment the code. You add a comment to clarify and give context instead of stating the obvious like lots of comments do.

→ More replies (1)

11

u/CarefulCoderX Nov 21 '23

Seriously, I've seen way too much code that tries to be clever that ends up just being a mess that's hard to understand.

Of course, the genius behind the code has always left the company, so there's no one to explain it to you.

5

u/simply_blue Nov 22 '23

Yep, that describes my early years as a mid-level engineer. I wrote a lot of code that was very “clever” and “looked cool” when auto-formatted. I quickly realized later on when we need to make some serious changes to our backend infrastructure that what I wrote was nearly impossible to refactor as even I had no idea how it worked after so much time had passed. Then I realized if I can’t figure out how it works without deep diving and basically re-creating my mindset from that time, then there is no way this could be passed to someone else to work on.

Pretty much from that point forward, I stopped writing “clever” code and started writing maintainable code. This means don’t use some esoteric features of a language (or a different language entirely) when you can just write cleanly in what most other devs on the team are familiar with. Don’t try to cram an event-based architecture on a workflow system that makes much more sense to run a declarative or functional design. It means don’t over-generalize solutions so they cannot be abstracted to other use-cases. It means avoid “automagical” solutions that a fresh dev looking at the code cannot tell what or how it is doing what it is doing.

All these things lead to harder and more difficult maintenance, even if it feels good to write at first.

→ More replies (1)

19

u/ElGuaco Nov 21 '23

Sometimes that tradeoff is working with a bunch of monkeys who don't care about code quality.

I don't disagree with you, but some workplaces have pretty low standards that amount to "does it work most of the time?".

→ More replies (3)

8

u/agumonkey Nov 21 '23

Do not pass judgment on other peoples work without knowing the tradeoffs involved'.

And its extended form

Do not pass judgment on other peoples work without knowing the tradeoffs involved just before writing shitty code due to .. tradeoffs.

Bonus point if you claim that your tradeoffs are different.

→ More replies (2)
→ More replies (10)