🎯 Featuring insights from 10 software engineers. Learn when to use comments to clarify, when they harm, and how to write clean, self-explanatory code with minimal clutter.
I prefer to add comments when I have to include the "WHY" this was done the way it is.
For example, we had a case where we couldn't migrate to the latest version of MySQL. Because of that, we had to do a tweak in the code, so then I added a comment and a link to the documentation describing why we had to do it that way.
I definitely agree that comments should focus on the WHY instead of the WHAT or HOW. I keep reminding developers that code is read more often than it is written so it should be optimized with that in mind...especially during outage scenarios. The last thing you want to do during an incident is question why something was done a certain way.
I prefer to add comments when I have to include the "WHY" this was done the way it is.
For example, we had a case where we couldn't migrate to the latest version of MySQL. Because of that, we had to do a tweak in the code, so then I added a comment and a link to the documentation describing why we had to do it that way.
Thanks for sharing your experience, Petar!
Recently renamed my regex to be meaningful and that was super cool 😎
For example:
```js
let startsWithBAndHasTwoDigitsCommaSeparated = new RegExp(/^B\d{2}(,B\d{2})*$/gm);
```
I definitely agree that comments should focus on the WHY instead of the WHAT or HOW. I keep reminding developers that code is read more often than it is written so it should be optimized with that in mind...especially during outage scenarios. The last thing you want to do during an incident is question why something was done a certain way.