Live data from Hacker News

There’s No Such Thing as Clean Code

steveonstuff.com

51–60 of 395 posts

Re: There’s No Such Thing as Clean Code

#51
post #27
post #5

Coding is a highly subjective and creative endeavor. "Clean code" is akin to "well written" for writers. Sure, you can analyze and even be able to define some good practices, but because we are always creating something new that has never done before, and the field is infinitely complex, no rules can be set in stone and applied across everything. In my opinion there's nothing wrong with calling code clean, we don't h…

Writing is a great metaphor: there aren't any hard-and-fast rules and there's certainly a subjective quality to it... but also, some writing is clearly better and some writing is clearly worse. Maybe there is no such thing as "good" writing because writing can be "good" in different ways or because we can never fully define what "good" means, but that doesn't mean that all writing is equal or that "everything is a tr…

> There are a lot of things we can't know exactly but that are still objective

Hmmmmmm not sure about that. AFAIK anything that we either can't measure objectively, or don't yet know how to measure objectively, is a subjective measurement, even if that measurement is subject to an objective apparatus (observer effect experiments; the measurement is subject to the circumstances of measurement)

Totally open to being wrong and you being right tho. Any examples come to mind for you?

Re: There’s No Such Thing as Clean Code

#52
post #29

Clean code is code that does what you expect it to do without many surprises. It is simple, not clever. Effortless to follow. Each part handles one idea at a time, at the same abstraction level. Doesn't force you to mentally juggle many balls at the same time. The code often tells you a story, it communicates how the programmer (author) described the problem, the solutions and the trade-offs. Very similar to writing.…

In my work history, I've never come across code like this, especially "effortless to follow". All the codebases I've worked with have been head scratch causing balls of mud. Am I unlucky or is what you are describing the rare exception?

To be honest, only around 10-15% of the time.

Often they were small dev teams in a small company that have high standards and given the trust & freedom to do things.

I think it boils down to how much the programmer actually cares and is given the necessary time to do a good job.

P.S: Been programming only for 6-7 years so can't say if my experience is any indicator.

Re: There’s No Such Thing as Clean Code

#53
I'm glad he brings up the much-maligned Singleton pattern as an object for debate - or beauty being in the eye of the beholder. "Clean" to me involves a range of classes and singletons (or better, all static code) in as close an approximation to use as they're a actually used in the final code. If something happens once only in your code, it's dumb to make it a class instance. If it happens twice but you know you will never need it again, same. If it happens repeatedly, refactor.

Clean code can be repetitive or concise. Readability is important, but only part of cleanliness. When you look at bad or dirty code you can tell immediately, because the logic is loose; it seems to try to handle edge cases at the end of a logic block, or catch errors that lead you to wonder why should this code ever encounter that error if the other code it's referring to is stable? Clean code displays confidence in knowing that edge cases are managed before they get to user functions.

Re: There’s No Such Thing as Clean Code

#54
post #29

Clean code is code that does what you expect it to do without many surprises. It is simple, not clever. Effortless to follow. Each part handles one idea at a time, at the same abstraction level. Doesn't force you to mentally juggle many balls at the same time. The code often tells you a story, it communicates how the programmer (author) described the problem, the solutions and the trade-offs. Very similar to writing.…

> The code often tells you a story

It sure does.

Unfortunately, the genre is quite often Lovecraftian Horror.

Re: There’s No Such Thing as Clean Code

#56

The fact that everyone can come up with his own definition of what "clean" is supposed to mean regarding code, tells us something very important about it: It has no intrinsic, defined meaning in the context of code. Saying code is "clean" is like saying food is "tasty"...its a personal opinion, not a defined term.

Strong disagree. It's defined meaning in the context of code is a subjective experience of the coder of "clean", which carries elements of "satisfying", among other things.

Maybe: It has no intrinsic, defined meaning in the context of the computing machine.

Re: There’s No Such Thing as Clean Code

#57
post #19
post #7

Earlier quoted context omitted.

Task: write code that does genetic programming by applying combination of 20 specific 5-line functions in random combinations and comparing results. My solution: array of lambdas Your solution: array of references to functions named f1 .. f20. Which is cleaner?

Are we allowed an array of references to functions with meaningful names?

Sure but the point was - sometimes there's no meaningful names, and the best description of a function is its definition.

That's why you write functions like this:

    def testXIsYAfterSettingAToBAndCToD():
        A = B;
        C = D;
        assert(X == Y);
So much meaning provided by the name ;)

Re: There’s No Such Thing as Clean Code

#58
post #29

Clean code is code that does what you expect it to do without many surprises. It is simple, not clever. Effortless to follow. Each part handles one idea at a time, at the same abstraction level. Doesn't force you to mentally juggle many balls at the same time. The code often tells you a story, it communicates how the programmer (author) described the problem, the solutions and the trade-offs. Very similar to writing.…

In my work history, I've never come across code like this, especially "effortless to follow". All the codebases I've worked with have been head scratch causing balls of mud. Am I unlucky or is what you are describing the rare exception?

Most corporate codebases I've encountered are, to put it mildly, unpleasant. In most cases, you've got dozens of people with varying skill and style maintaining the stuff over a decade or more. New business requirements are patched on top, without ever considering the whole architecture.

The cleanest codebases are those where the project has a focused goal and is maintained by a few developers with a low churn rate.

Re: There’s No Such Thing as Clean Code

#59
The Uncle Bob Martin definition of "clean code" from his book "Clean Code: A Handbook of Agile Software Craftsmanship" is a set of rules that absolutely are not at odds with one another. If you follow them you will end up with code that's really nice to read and easier to maintain, and, most importantly, that you can confidently change.

There's a decent summary here - https://gist.github.com/wojteklu/73c6914cc446146b8b533c0988c...

Re: There’s No Such Thing as Clean Code

#60
So many developers say "clean code" when they mean "familiar code" and "familiar coding patterns". One person's clean code is another's heap of spaghetti. Idioms (like Duff's device, assignments in conditionals, function chaining) can be clean code if you apply it appropriately and your developers recognize it. Strict class hierarchies can be dirty code if you need to move gigabits in real time with 10 µs latency.

Kids don't like broccoli because they haven't tasted broccoli.

Post reply on HN