4 ms·
> Without comments the only way the next guy has a chance to understand the code is if you stick to lowest common denominator patterns and frameworks. Or -
by the8472 10y ago
> Without comments the only way the next guy has a chance to understand the code is if you stick to lowest common denominator patterns and frameworks.
Or
- read the tests for that method.
- look at the commit log and associated bugs.
- use identifiers that are self-explanatory to some extent. auto-complete makes using long names manageable.
- step through it with a debugger to see what it does.
- use an editor/IDE that shows additional info about unknown methods, assuming a statically typed language
where it has total knowledge about available types.
Comments are certainly one way to understand code, but not the only way.
- Tarrosion 10y agoMany of the techniques you listed are subcategories of reverse engineering. In an ideal world, the code and comments are clear enough that no reverse engineering is necessary. Given a bizarre method, would you rather see a clear comment or spend half an hour stomping through a commit log?
- falcolas 10y ago> In an ideal world, the code and comments are clear enough that no reverse engineering is necessary. In an ideal world, perhaps. But in the real world, the comments contradict the code, the code attempts to use a software pattern which doesn't quite fit (and thus requires a large number of hacks to make it fit), so reverse engineering is your only real choice. Aiming for an ideal world is never a bad thing, but even if I saw well documented code, I wouldn't trust it. The only difference is that after reverse engineering it anyways, I might feel a bit of surprise when I find that the comments were, indeed, correct.