Well written software needs few comments

By 1 ChrisGarrod on August 16, 2007

/ machine language assist for 11/40
#!/bin/sh # is not really a comment
# may be the most common comment delimiter
/* make a C claim */
// another claim C++
C FORTRAN ISNT FUNNY
; put this in your .exrc
<! Html has it's own form >
REM BASIC IS FOR KIDS

Embed Claim Make a related claim

Discussion (9)

http://steven.bitsetters.com/

1 Steven Osborn who agreed, says

If you said no comments I would have to agree. But well written, structured code shouldn't have needless comments.

// save the file
file.save();

// close the file
file.close();

Make a related claim about 1 year ago (link)
http://steven.bitsetters.com/

1 Steven Osborn who agreed, says

If you said no comments I would have to _disagree_.
d'oh

Make a related claim about 1 year ago (link)
http://www.tapsellferrier.co.uk/nicferrier/

8 nic who agreed, says

Well, that's obvious steven.

But I think there's more going on here. SICP (which is the best computer book ever written) suggests that code is the programmers chief communication mechanism.

I believe that.

I also think that comments tend to be maintained less than code, or out of step with code.

Of course, all those things can be mitigated by having a good project manager. I've been following emacs development closely just recently and saw rms crit some code destined for emacs trunk because it didn't have enough comments.

I know very well that while rms is looking after emacs he will ensure that all the comments are maintained as well as the code.

But that isn't always the code. In fact, it's the only personal example I have of commenting being entirely a safe maintainable thing to do.

Make a related claim about 1 year ago (link)
http://www.brucestockwell.net/

3 T3H who agreed, says

I really don't find these kinds of comments useful.

// save the file

file.save();

I'd much rather read a summary that tells me the goals of a class or function and how it fits in with the system. Summary comments don't suffer rot as quickly as direct inline comments.

I also like to see comments on code that works around, say a virtual machine bug or something of that nature.

Make a related claim about 1 year ago (link)
http://zebruh.myopenid.com/

1 Worth Considering who agreed, says

fewER comments, anyway.

Make a related claim about 1 year ago (link)
http://cerebralsilicate.myopenid.com/

3 Alistair Young who disagreed, says

It needs few/no comments to explain what it's doing.

But it still needs comments to explain why it's doing it, and why that way.

Make a related claim about 1 year ago (link)
http://tenebrus.myopenid.com/

2 tenebrus who disagreed, says

+1 Alistair
Furthermore, well-written code is not always read by the most clueful people. Sometimes, they need that helpful hand.

Make a related claim 6 days ago (link)
http://tenebrus.myopenid.com/

2 tenebrus who disagreed, says

But yeah...

// close the file

file.close( );

is pretty dumb.

Make a related claim 6 days ago (link)
http://wyrframe.myopenid.com/

1 Wyrframe who agreed, says

Documentation, yes. I prefer to see inline comments only in two scenarios...

a) they constitute documentation (function/method pre/post conditions, argument interpretation, return values, etc); OR...

b) if a function/method is being called that might induce side-effects that will affect the current function/method's execution flow.

For the record, object-oriented programming and stateful-object programming do not belong in bed together. If you have a sorted list, and it has a setSortOrder() method, YOU ARE DOING IT WRONG. If you have an Excel-style Workbook object, and it has operations like SetActiveSheet(name) and SetActiveCell(address) and EditActiveCell(newvalue), YOU ARE DOING IT WRONG.

Sign in in to leave a comment.