News for hackers. Stuff that matters.
Re:Should I Comment My Code? The Case Against Code Comments by madeofpalk on Thursday October 06, 2016 @08:50AM (#12651961)
And a comment explaining why is especially useful when the code is a bit more dense and hard to follow - which is unavoidable at times.

IMHO, your default mode should be to not to comment because you should instead focus on 'code as comments' - the code should be easy enough to read that it explains itself. Occasionally (for the reasons you pointed out) you need to fall back to english prose to explain those 'whys'.

Re:Should I Comment My Code? The Case Against Code Comments by wangchow on Thursday October 06, 2016 @09:37AM (#12652302)
I think this is one of those things that is more about wisdom than anything else. You get a sense of what to comment over time and experience.

Typically following language best-practices is ideal (pydoc, godoc, Javadoc, etc) so you can get easily-generated documentation for free. Following the standards will make any custom APIs consistent with the standard library API docs.

The most important thing though is to ask for peer review on the code. When you are writing code (just like regular language) it will make sense to you regardless of comments or proper variable names. Have someone else read it and tell you what the confusing bits are. If there is no one to do that because you're a lone wolf, then step away from the work for a couple days and play golf or something. Then come back, read the code, and ask if it could be more clear. Then either change variable names or add comments for clarification.

Re:Should I Comment My Code? The Case Against Code Comments by Xylakant on Thursday October 06, 2016 @08:54AM (#12651984)
on top of that the why can extend as to why this specific implementation route was chosen. Some algorithms are less efficient in a general case, but may be much more suitable to the specific case at hand. Things that were tried and proven not to work even though they seem beneficial at first glance.