3 ms·
Nope. In my career I've never seen this mythical code that doesn't need comments. Tell me about preconditions, postconditions, performance characteristics, quir
by bluesnowmonkey 11y ago
Nope. In my career I've never seen this mythical code that doesn't need comments. Tell me about preconditions, postconditions, performance characteristics, quirks, absolutely anything and everything that could affect the caller.
- csours 11y agoOne of my favorites was a hex string (ascii) to binary string (ascii) converter that ran all on one line. I think my colleague found it online, because they were nowhere near technical enough to implement it, let alone on a single line. Nary a comment or clue in the context to figure out why or what it was doing. I broke it into 3 lines and commented each.
- Ma8ee 11y agoThe point is that writing comments isn't a substitute for writing clear code. I have seen way too much code that someone puked up without thinking about readability, and then tried to save it by sprinkling it with comments. So the first thought when writing code that isn't obvious should not be to comment it, but to figure out if there is a way to write it clearer. But of course, sometimes we need to write code that isn't obvious, and then a few well thought through comments will save the day.
- joshka 11y agoI've often seen assertions like this that all / most code requires comments. I hold a personal view that it's actually the opposite, but can't seem to get anyone above to bite and show me useful real code provides a counterpoint to my view. Can you point to an open source repo somewhere that demonstrates your point that comments are preferable to writing clear code without comments? I'm sure you can point to repos where poorly written code requires comments in order to be properly explained. This is not really what I'm after, as I'd contend it's likely that writing the code better would be more useful to that project.