Hacker News new | ask | show | jobs
by commanda 4924 days ago
I helped the author edit this post for clarity, but it took all I had not to argue with him because I strongly disagree with his thesis. My main language (Objective-C) is relatively less readable (compared to his main language of Python), and I would absolutely not be able to function in a team, or even with code I'd written myself over a week ago, without heavy commenting. I do believe he's right though with respect to test coverage being effectively a runnable comment or explanation of how a particular module works. However, to me at least, tests are no more readable than the source code itself, so I still rely (and implore my teammates to rely) on heavily commenting their code. Especially when dealing with inscrutable things like OpenGL code.
1 comments

Not to mention code is imperfect. My main platform is Obj-C/iOS and there are numerous API bugs, workarounds, and bits of ugliness involved when integrating with third-party APIs and libraries. These definitely involve comments because they are incantations that have a reason for existing, where the reason is entirely non-obvious on examination.

God help the guy who rips out a seemingly innocuous line of code only to subtly break things underneath. Even a simple:

    // Hack around time parsing bug in iOS3+, see [StackOverflow thread]
saves hours of lost productivity.

We can get rid of comments the moment we invent a perfectly expressive language, where every single line of code in your entire stack is under your control and everything works exactly as advertised out of the box.

Until then, I'll keep commenting where I need to, and never when I don't.