He who sacrifices clarity for correctness deserves neither
The claim (a riff of a paraphrase of an old quote) is that when confronted with what appears to be a hard tradeoff between clarity and correctness, work hard to avoid sacrificing clarity. Quite often, people concerned with correctness ignore clarity.
-
-
The unfortunate consequence is that unclear code is rarely correct.
-
I think that's a claim that would need to be backed up by a study. Often I've personally found that unclear code is unclear for a reason, such as contorting around a business requirement.
-
The underlying business requirement can be turned into an encapsulating abstraction with a name. Same crappy code, easy to "chunk" in other parts of the code. In a case I'm working on right now, naming the abstraction also provides a good place for a warning about dangers.
-
I don't mean a framework or big abstraction. Just finding a way to get the code out of places it doesn't belong. In these contorted cases, I've often found that compliance is haphazard, but hard to audit because nobody can memorize the full description of the correct behavior.
-
What would be an example of code where making it more clear would compromise correctness?
End of conversation
New conversation -
-
-
The opposite is true too, though: I've run into cases where people are concerned with how nice things look and how 'readable' the code is at the cost of making it hard to test, document, or analyze. It's about finding optimum point, which is a hard question.
-
Yep. I agree completely. I think people give up too easily, confuse "pretty" with "clear" (which has domain-specific meaning), and confuse explicit with correct. Clarity means being explicit about important distinctions and abstracting unimportant details. Again, domain specific
-
Example: by default, Rails signs and verifies cookies using bcrypt. This is more correct than making every app make an explicit decision about whether to use signed cookies, and if so, which encryption to use. Explicit is not always the same as more correct.
End of conversation
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.