Live data from Hacker News

CodeThatDocumentsItselfSoWellItDoesNotNeedComments

thedailywtf.com

1–10 of 40 posts

Re: CodeThatDocumentsItselfSoWellItDoesNotNeedComments

#6
I'll come out of the closet and admit that I like descriptive names. There's a point they get ludicrous, but that's also a very clear sign the concept they're representing has become confusing and unwieldy too. If you can't come up with a name that's both clear and short, maybe the function's purpose is also unclear.

After many years of maintaining large codebases written by other people, the comments are very seldom useful, and often actively misleading, thanks to code changes over time. Coders seem a lot more reluctant to change a function so it no longer does what the name implies than they are to modify code without updating the comments.

Re: CodeThatDocumentsItselfSoWellItDoesNotNeedComments

#8

I'll come out of the closet and admit that I like descriptive names. There's a point they get ludicrous, but that's also a very clear sign the concept they're representing has become confusing and unwieldy too. If you can't come up with a name that's both clear and short, maybe the function's purpose is also unclear. After many years of maintaining large codebases written by other people, the comments are very seldom…

I'm with you all the way on descriptive names.

As for comments though, in my experience they can be extremely useful. And I don't mean just one liner's but a couple sentences here and there explaining what you're doing and why you're doing it.

Agree with you also though, that often a coder working with someone else's base won't take the time to do it. I think this is because we naturally take less pride in maintenance work then we do in the creation of an application.

Re: CodeThatDocumentsItselfSoWellItDoesNotNeedComments

#9
post #5

This example is only really annoying because the items were almost full sentences. I prefer small 2-3 word functions. But really, like pmichaud said, I'd rather support this than, say, reverse engineer Google Analytics code http://www.google-analytics.com/ga.js

Obviously the Google Analytics people didn't actually write that terrible mess. They used code compression software to obfuscate it and reduce its size.

But seriously, two to three word functions and variables aren't bad. Technically though C++ variables have a max size of 255 characters. At least that is what I seem to remember. Am I right?

Re: CodeThatDocumentsItselfSoWellItDoesNotNeedComments

#10
post #7
post #3

I would rather support that, than most of the code I've actually been asked to support.

Is it really all that difficult to throw in a comment explaining what it is you're trying to do when it's not obvious to someone other than yourself?

Eliminating _all_ comments is a little extreme, but if faced with the choice between excessively long names and insufficiently descriptive names, I'll go with excessively long every time.

I've spent way too many months digging around in Fortran code where every variable and function name was less than eight characters (actually the eight-character limit has been gone since Fortran 77, but some people still insist on writing Fortran 90 as if it were Fortran 4).

Post reply on HN