re: 10 practices for writing readable code VIEW POST

TOP OF THREAD FULL DISCUSSION
re: It sometimes just is. You can have something as simple as: return x / 3; and in the absence of a comment you can't tell whether that was suppose...

A good rule of thumb is to comment about the 'why' and not the 'how' or 'what'. This means that the comments that are left are the ones that aren't obvious from the code.

Of course, as with anything there are exceptions, such as dealing with magic values from external sources or one that I've had to do recently: comment what a series of regular expressions were doing!

Another favourite of mine is when the production code has checks for something that's injected only for tests. To add insult to injury, those tests are usually called... wait for it... unit tests!

Otherwise, yes, that looks like a sensible rule.

code of conduct - report abuse