Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

9
  • 3
    "For most projects, comments are the primary (if not only) form of project documentation." - tempting to downvote for this but unfortunately it must be admitted as a true statement. I hope though that it is not your intention to claim that this is how things should be. Commented May 14, 2012 at 6:59
  • 2
    I really disagree with this, as the only reliable documentation you have is the source code itself. Both comments and "documentation" have to be maintained with the code, which seldom happens. So the only reliable source of documentation is your code!
    – martiert
    Commented May 14, 2012 at 7:18
  • 4
    @martiert I used to feel the same way, but I found this doesn't really work as well in practice. All of those "why" comments are much clearer as comments than trying to extract "why" knowledge from code. Certainly self-documentation code can (and should) be used to remove most comments, but sometimes a comment is the simplest, clearest, and most time efficient way to document something.
    – Oleksi
    Commented May 14, 2012 at 13:50
  • 5
    @martiert The problem with self-documenting code is that it doesn't permit references to documentation elsewhere. Some of the best comments in code that I've ever seen have been references to academic papers that explained the details of the algorithm used or the selection of magic constants. No amount of self-documenting is going to help avoid the fact that some, critical, documentation is just plain non-obvious. The “why” often falls in this category, and sometimes the “how” does too. Commented May 14, 2012 at 14:48
  • 3
    Also note that comments, in many languages, are used to generate the actual documentation... so they're are often one and the same. See the MSDN as an example. Commented May 14, 2012 at 16:40