Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It's fairly ironic that you've spent so many words re-iterating the argument that "code should be self-documenting".

You're right that comments don't maintain themselves, though. That's the job of a programmer, and if the programmer isn't doing their job, they probably shouldn't be working on a project with other people.



Um.

You're right that code doesn't compile itself, though. That's the job of the computer operator, who takes the code I write in my notebook and flips the corresponding switches on the computer. If the computer operator isn't doing their job, they probably shouldn't be working on a project with other people.

People are fallible. People make mistakes. People get bored. That's why we write tools to do our work for us. The way we avoid making mistakes is by making the mistakes impossible in the first place. This is why typing exists, because without static type checking, people will mix up their types. Yes, it's the job of the programmer to keep their types straight. The compiler doesn't care about types. So what? The whole point of tools is to make the life of the programmer easier, not by magically transforming them into perfect programmers who never make mistakes, but to have tools that avoid, check, verify and catch those mistakes.

Comments circumvent any such tools. Suddenly, you are back to banging rocks together.


Ah yes...the "humans make mistakes, so therefore we should completely ignore all concessions to the people who maintain the system" argument.

Those pesky humans will be much less problematic if they can't communicate in their imprecise meatspeak.


I don't think you understand what I'm saying.

The people who maintain the system are not helped by incorrect information. The information describing how the code works in comments is invariably incorrect. None of the tools we usually employ (unit tests, regression tests, compilation, etc.) apply to the comments, and describing the HOW of code in comments breaks the DRY rule unless the comments ARE the code.

Now, as I said, sometimes you need to describe intent. Most of the time, that is better done through liberal use of functions, purpose-specific types and function names.

For example: In C, there are multiple types of integers defined that all reduce to roughly the same types: size_t, ptrdiff_t, etc. Does the compiler care if the type is unsigned int or size_t? No. Apart from the portability reason for using these types, the other is to describe intent. A variable of the type size_t should store a size. Now, we could make the variable an unsigned int, and in a comment say that "this variable stores a size". But will this comment stay in sync with the code, when the variable later changes to a ptrdiff_t because it is now used to compare pointers? No. The comment won't get changed, because humans are fallible, and changing the comment would require making the same change in two places, one of which is ignored by the toolchain.


Yeah, I got it. Machines can't verify the documentation that humans write. It's not a subtle point.

Now, if the code were good enough to substitute for human-written documentation, you'd actually be addressing my argument. The people who argue that code is self-documenting tend to produce only badly documented code.

The way that comments stay in sync with code is that the developer keeps the comments up to date. It isn't that hard.


Documentation is something completely different from comments. Documentation is something you write for the interfaces you expose. This, I have absolutely no problem with. Interfaces are meant to be stable, they should be well defined, they should have human-friendly instructions and examples on use.

Comments in code? That's something completely different.


> It's fairly ironic that you've spent so many words re-iterating the argument that "code should be self-documenting".

It would be ironic if it was being argued that natural languages are bad. But that is not what's being argued, and the author of that comments was not trying to convey an algorithm to you.

> That's the job of a programmer, and if the programmer isn't doing their job [...]

This is puritanism. Just because it's work, doesn't mean it's useful.


Documenting your code is Puritanism?

Human communication is the rate-limiting process for all software teams. Individual productivity is almost entirely irrelevant, if your personal productivity means that you slow down ten other people.


As i said in a comment further down: Comments are not documentation.

Documentation explains how to use the exposed API to get the code to do something the user desires. It does however not describe what the code does, or why a specific bit of code is done in a certain way.

Comments do not concern themselves with the API, they also do not describe what the code does, that task is up to the code by way of structuring and proper naming of variables and functions.

What is left to the comments is to explain to the guy coming in afterwards why a certain bit of code is as it is when the code or the documentation cannot adequately explain its purpose explicitly or implicitly.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: