3 ms·
> There’s no such thing as clean code. > ‘Clean’ isn’t a measure of anything useful. Code can’t be clean simply because ‘clean’ doesn’t describe anything about
by RangerScience 5y ago
> There’s no such thing as clean code.
> ‘Clean’ isn’t a measure of anything useful. Code can’t be clean simply because ‘clean’ doesn’t describe anything about code.
Ehhhh. There is absolutely such a thing as clean code. But yes; what there isn't a way to measure code cleanliness (although there's lots of surrogate measures; see every linter) which means there's also no way to render it into a dogma...
...and to (perhaps) stick my foot in it, that's something that gets harder to grok the less important subjective human experience is to you. IMHO, this is part of why Ruby code has an easier time being cleaner (and can reach high levels of "clean") - subjective human experience is baked into the language.
(note: yes, you can absolutely write dumpster fires in Ruby, arguably easier than you can in Java; and you can absolutely write very clean code on Java and any other language)
> I’ve come to the conclusion that often when we describe code as ‘clean’ when we think it’s good but we’re not entirely sure why. It just feels like the right solution.
Yes, absolutely. There's a lot of things in popular wisdom that are signposts for "there's more here if you pay attention".
> absolve you from having to justify that with more concrete rationale.
...Why in the hell do you need absolution here in the first place?! What are you being absolved from?
(shameless quote: justice only matters to the just)
> you don’t really need clean code, you need _____ code
No. That's the trap of Goodhart's Law. You need something outside of your metrics so that your metrics don't become your target.
- coldtea 5y ago>Ehhhh. There is absolutely such a thing as clean code. But yes; what there isn't a way to measure code cleanliness Well, in several epistemologies the second admission means there's no such a thing (or that, it might as well not exist).
- parminya 5y ago> No. That's the trap of Goodhart's Law. You need something outside of your metrics so that your metrics don't become your target. How can you make a metric out of "we aren't really sure what the direction of change for this feature is going to be, so it should be easy to refactor"? and why would that metric be any more likely to fall victim to Goodhart's Law than "the code should be clean"?
- RangerScience 5y ago"Easy to refactor", AFAIK, can be approximated via LoC within functions and classes; dimensionality of functions; cyclomatic complexity; etc. Those are the metrics; you can produce reasonable and grounded numerical measurements of them. But, if you were to just optimize for those metrics, I bet you'd run into issues, whereas if you use those metrics as part of your process for determining if it's easy to refactor, then yeah, I'd expect you to be less vulnerable to Goodhart's Law. "Easy to refactor" is a goal, not a metric; low cyclomatic complexity is a metric, not a goal. IMO.