Add explanatory comments when code logic is unclear, implements workarounds, or has special reasoning that isn't immediately apparent to other developers. Comments should explain the "why" behind the implementation, not just the "what".
Add explanatory comments when code logic is unclear, implements workarounds, or has special reasoning that isn’t immediately apparent to other developers. Comments should explain the “why” behind the implementation, not just the “what”.
This includes:
Example:
// Fetch a dynamic import and re-try 3 times with a 2-second back-off
// See GitHub issue #1234 - this works around intermittent module loading failures
function retryImport(modulePath) {
// implementation here
}
onStudioTestFileChange(filePath) {
// wait for the studio test file to be written to disk, then reload the test
return this.onTestFileChange(filePath).then(() => {
// rest of implementation
})
}
The goal is to make code self-documenting and reduce the cognitive load for future maintainers who need to understand the reasoning behind implementation decisions.
Enter the URL of a public GitHub repository