Think about it has a general picture description vs a description pixel by pixel. Both have value depending on what you need.
Isn't this a variation on "who needs comments anyway, just read the code?"
That's not what this "TLDR plugin" does, because there is no magical translation. You put whatever you want in there. I think this is obvious.
Ironically, you basically rephrased the title, while objecting to it's use?
> Comments explain why the code is there
> TLDR explains what a piece of code does
It's still not clear how this explanation is supposed to be sufficient to explain the conclusion.
If a comment is collapsed in an IDE and you spend 1 click/key combo to expand it, versus some key combination to pull up the TLDR, the difference is what?
Comments being embedded IN code could be a thing of the past. No PR necessary to maintain them. Sounds like an improvement to me.
The function adds 5 to i, and if j is less than three, the function sets it to 2.
Does it describe this code?
function f() {
i = i + 5;
if (j < 3) {
j = 2; // <--
}
}
... or does it describe this code? function f() {
i = i + 5;
if (j < 3) {
i = 2; // <--
}
}
The answer is yes, and this is ultimately why we use programming languages rather than natural language to instruct computers.In the English you can recognize the ambiguous parse and reject it.
Natural language doesn't have such rules. My example above isn't an example of incorrect English, there isn't a correct interpretation. The grammar is correct and both interpretations are correct.
The comments then should then be reserved for the cases where it is not obvious why or how something is done, or for assumptions that can't be expressed through code (type system or similar).
So instead of having the following
// set i equal to five
i = 5;
either skip the comment, or, since 5 might seem arbitrary, comment why 5: // first four slots are reserved
i = 5;