2 ms·
When you're writing code, you have your problem, and you're trying to figure out how to make the computer solve it for you. When you're reading code, you have t
by ajnin 5y ago
When you're writing code, you have your problem, and you're trying to figure out how to make the computer solve it for you. When you're reading code, you have the detailed computer steps and you need to figure out what the problem was in the first place. Two very different tasks. Self-documenting code helps you with that by encoding natural language explanations directly in the code by naming things appropriately. But to explain to other developers and your future self how you got there then you need comments. A sort of map of all the paths your mind went though to solve the problem, why the obvious solution was in fact a dead end, why you did or didn't take a shortcut and so on.