6 ms·
I agree, these are cases when you need comments inlined in the code. Describing what a single code is doing is only useful, if the comment is easier to read th
by trashtester 4y ago
I agree, these are cases when you need comments inlined in the code.
Describing what a single code is doing is only useful, if the comment is easier to read than the code itself. That can be useful for arcane cases, such as dirty regular expressions, bash scripts with several layers of pipes, or non-standard pointer manipulation in C.
Much more important, is the why, as in your example.
But there is also the what when it applies to code design that spans more than a few lines of code. This requires documentation. As long as we follow a design pattern, the documentation is covered by the pattern description.
But if we invent a novel design, either a one-off or a new design pattern, it needs to be described in text and figures, not just inline in the code.
Similarly, and even to some extent when staying inside a design pattern, object models need a conseptual design, where the ideas and purposes behind each class or interface is explained, as well as where the relationships between classes are visualised.
- hinkley 4y agoCommit messages and calling people out for breaking commit message history works to an extent. If you can keep someone from breaking commit history badly enough. I still maintain we're awaiting another generation of version control where commentary on code is cumulative, instead of just set at the time of commit.
- joshka 4y agoYeah, it's hard to retrospectively unbreak commit history on legacy projects. Git notes[1] might be a possible solution, but I've not had that be particularly useful in practice (due to lack of support in various other systems). [1]: https://git-scm.com/docs/git-notes https://git-scm.com/docs/git-notes