Live data from Hacker News

There’s No Such Thing as Clean Code

steveonstuff.com

11–20 of 395 posts

Re: There’s No Such Thing as Clean Code

#11
In my 5th role where I write code, and I have dealt with so many different approaches and definitions of "best practice" that at this point I just roll over to whatever the generally agreed approach is at my current org and mimic it as best as possible.

In one organization, I have even had two seniors go back and forth telling me to remove what the other senior told me to put in.

The entire process of defining "clean code" seems painfully arbitrary.

Re: There’s No Such Thing as Clean Code

#13

Theres definitely clean code, theres just no rule book for how to define it or course you can teach for how to write it. Some people are just better at the art of writing simple software. You definitely know it when you see it.

I agree. The article (well the little I read of its unreadably thin font) doesn't even really argue that there's no such thing as clean code, just that it's not very well defined.

Well sure, but that's like saying "there's no such thing as beauty" or "there's no such thing as a well-written book". Clearly bullshit. They might be somewhat subjective and have no mathematical definition but they clearly exist.

Re: There’s No Such Thing as Clean Code

#14

Earlier quoted context omitted.

20 short functions definitely sound as though they should be explicit. Named, documented, testable. 1 or 2 you could get away with being implicit. 20 requires a lot of understanding as to what's going on!

Wait until you work on a 100k line code base where someone enforced this kind of thing

Fair enough - I haven't done that. I'd be surprised if having loads of anonymous, untested functions would make such a thing more manageable, though.

Re: There’s No Such Thing as Clean Code

#15
post #7

Earlier quoted context omitted.

20 short functions definitely sound as though they should be explicit. Named, documented, testable. 1 or 2 you could get away with being implicit. 20 requires a lot of understanding as to what's going on!

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?

ts/js: I see no problem?

* if anyone not get it, ts/js can declare a key-value lambda like:

let myFunc = {f1: () => , f2: () => } and so on. It can be called by string key like myFunc["f1"](), and all it's props can be get by Object.keys(myFunc) so it can be randomized easily.

Re: There’s No Such Thing as Clean Code

#16
Just because "clean" connects to a lot of concepts doesn't mean "clean" code is meaningless, any more than clean dishes. A plate smeared with tar is not clean, no matter if the tar is sterile, and a plate which has been sprayed with salmonella isn't clean, even if you can't see the contaminant. These are different dimensions of "clean", but still very much meaningful.

I personally like "clean" as a term for code quality. We've all seen how focusing on easily measurable metrics (like code coverage) can help, but in the hands of the saboteur or the clueless it just becomes a meaningless number. "Clean", instead, focuses on the ultimately human judgement of how to make code which is fit for purpose.

Re: There’s No Such Thing as Clean Code

#17
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…

I'm not giving up on clean code, but at the last 5 years I pursuit separation of pure function and unpure function more than clean code. It makes easier to debug / unit tests.

That sounds like clean code ;)

Re: There’s No Such Thing as Clean Code

#18
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…

I'm not giving up on clean code, but at the last 5 years I pursuit separation of pure function and unpure function more than clean code. It makes easier to debug / unit tests.

[deleted]

Re: There’s No Such Thing as Clean Code

#19
post #7

Earlier quoted context omitted.

20 short functions definitely sound as though they should be explicit. Named, documented, testable. 1 or 2 you could get away with being implicit. 20 requires a lot of understanding as to what's going on!

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?

Re: There’s No Such Thing as Clean Code

#20
post #7

Earlier quoted context omitted.

20 short functions definitely sound as though they should be explicit. Named, documented, testable. 1 or 2 you could get away with being implicit. 20 requires a lot of understanding as to what's going on!

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?

Not that I am taking a stance here, but you didn't really engage with the GP saying that having functions instead of lambdas allows one to name, test and document them: in fact, they might not be called f1 to f20, in fact they might have docstrings (I guess one could comment lambdas, but see it rarely) and you couldn't test lambdas unless you assign them, i.e. give them a name i.e. turn them into functions in all but name.
Post reply on HN