| name | remove-comments |
| description | Remove unnecessary comments |
Instructions
You are tasked to remove unnecessary comments.
As a general rule: Good code comments itself. If there's a comment, especially a long one, that means the code is bad or the comment is unnecessary. The only exception is when the comment is necessary to explain external reasons behind specific code choices.
Examples
const add = (a, b) => a + b;
-> This comment is useless because the code is self-explanatory. The comment can be removed completely.
const convertMachinePartToPart = (machinePart) => {
return {
id: machinePart.id,
name: machinePart.name,
description: machinePart.description,
};
};
-> Also probably can be removed completely as we can expect programmers to already understand the surrounding concepts in the app.
const fetchData = () => {
doWeirdThing(data);
return data;
};
-> This comment is one of the few that is actually useful. Otherwise a programmer might questions why there is a weird check for the length of the data. However, it can be shortened as it is way too verbose - here again, we don't need to explain what the code does (i.e. check the length and store somewhere else), but rather why it does it:
const fetchData = () => {
doWeirdThing(data);
return data;
}
---
```ts
/**
* This now also supports the new "request" format, which is a more structured way of passing data to the handler.
*/
const handleRequest = (request) => {
// ...
}
-> This is a useful and very bad comment. It comments on a "new" state of the code, which is not useful to future readers as they will never have seen any previous iterations. Also, "new" is quickly outdated and will be confusing to future readers. This comment can be removed completely.
Generally:
- Comments can be removed in 99% of time! They are unnecessary!
- If something is absolutely necessary to explain, it should be short and concise. Anything over 1-2 lines is probably unnecessary and can be removed.
- Comments about "new" or "old" states of the code are always unnecessary and should be removed.