Comments should only be used when they genuinely add value to the code. Avoid redundant comments that merely restate what the code does, as they waste time and mental energy. Keeping comments in sync with the code can be difficult, so reserve them for when they are truly necessary. As Kent Beck notes, unnecessary comments incur costs without benefits and should be deleted ([[References#^7454b3|Beck, 2024]]). So, [[Delete unuseful comments]].
The best times to write comments are before you start coding, when following a [[Documentation-Driven Development (DDD)]] approach, or after thoroughly reviewing and understanding complex code.
Effective [[Coding involves writing]] with the reader in mind, so providing clear and explanatory comments is essential.