3 ms·
> You need to use comments to explain the code – Code should be able to explain itself and should be in a format that is easily readable. If you find yourself n
by buugs 17y ago
> You need to use comments to explain the code – Code should be able to explain itself and should be in a format that is easily readable. If you find yourself needing to explain what your code is doing then you may want to look into rewriting that code.
EDIT: This is not referring to using comments (e.g. javadoc) to explain the purpose of a method/class and its inputs and outputs.
-- What? --
- fnid 17y agoThis is only true of "unclever" code. You haven't written a lot of code if you haven't found a concise, optimized, abstract way to solve problems that aren't intuitive when first seen with the naked eye. We aren't writing books, we're writing instructions for a computer and those two things can sometimes be very, very different.
- groby_b 17y agoOh dear god, that nonsense again. That might be true when you write boring, straightforward business code. But when you implement a complex algorithm, that's just silly. It's also silly if, for example, you need to do "clever" things for performance reasons. Any comment that explains the why behind your code is a good comment.
- eru 17y agoSee the recently discussed square-root approximation algorithm as an example.