[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

[OT] Comments Are More Important Than Code

Tim Hunter

4/27/2005 12:46:00 PM

Even if this is not directly about Ruby, both Jeff Raskin and the
subject have come up before on this n.g. so I believe it's not
altogether off-topic...

Comments Are More Important Than Code

http://acmqueue.com/modules.php?name=Content&pa=showpage&a...
65 Answers

Jim Menard

4/27/2005 1:31:00 PM

0

Tim Hunter wrote:
> Even if this is not directly about Ruby, both Jeff Raskin and the
> subject have come up before on this n.g. so I believe it's not
> altogether off-topic...
>
> Comments Are More Important Than Code
>
> http://acmqueue.com/modules.php?name=Content&pa=showpage&a...

Yes, but...

A few days ago, I noticed that a method in the Squeak (Smalltalk) core
collection classes did one thing, while its comment said another. That method
has probably been around for thirty years or so; the Smalltalk collection
classes have a long history.

Which is correct? The code, because the behavior takes precedence, or the
comment, because it expresses the intention?

I don't know the answer; nobody on the Squeak mailing list has yet responded
to my query about whether the code should be changed or the comment.

Jim
--
Jim Menard, jimm@io.com, http://www.io...
"Indeed, an upsettingly large part of academia right now seems to be
working on bringing Java into the 1980s... sigh." -- Avi Bryant



Robert Klemme

4/27/2005 1:40:00 PM

0


"Tim Hunter" <sastph@sas.com> schrieb im Newsbeitrag
news:d4o1i0$bd3$1@license1.unx.sas.com...
> Even if this is not directly about Ruby, both Jeff Raskin and the
> subject have come up before on this n.g. so I believe it's not
> altogether off-topic...
>
> Comments Are More Important Than Code
>
> http://acmqueue.com/modules.php?name=Content&pa=showpage&a...

There's some truth in this.

"Many become so laconic that you have to understand the code to be able to
interpret the comment." - very nice. :-)

"Ideally, comment should be the default, with a way to signal the
occasional lines of code." - sounds like he would be a friend of
http://www.literateprogra... and especially
http://www.ross.net/...

Kind regards

robert

Ara.T.Howard

4/27/2005 2:09:00 PM

0

james_b

4/27/2005 2:14:00 PM

0

Jim Menard wrote:
> Tim Hunter wrote:
>
>> Even if this is not directly about Ruby, both Jeff Raskin and the
>> subject have come up before on this n.g. so I believe it's not
>> altogether off-topic...
>>
>> Comments Are More Important Than Code
>>
>> http://acmqueue.com/modules.php?name=Content&pa=showpage&a...
>
>
> Yes, but...
>
> A few days ago, I noticed that a method in the Squeak (Smalltalk) core
> collection classes did one thing, while its comment said another. That
> method has probably been around for thirty years or so; the Smalltalk
> collection classes have a long history.
>
> Which is correct? The code, because the behavior takes precedence, or
> the comment, because it expresses the intention?


Ideally, in CDD (comment-driven development), the comments would be
written first, then the code (including unit tests) written in such a
way that comments are not needed to describe behavior (though they may
still be needed to explain design trade-offs or a broader intent).

>
> I don't know the answer; nobody on the Squeak mailing list has yet
> responded to my query about whether the code should be changed or the
> comment.

A problem, but without the comments there may possibly be incorrect code
with no (obvious) indication that something might be askew.

(One might hope that unit tests would allow the dubious code to be
changed and tested to see which is correct, the comments or the code.)


James

--

http://www.ru...
http://www.r...
http://catapult.rub...
http://orbjson.rub...
http://ooo4r.rub...
http://www.jame...


Tom Ayerst

4/27/2005 2:19:00 PM

0

This is something of a Straw man argument. In the article Raskin says:

"I discard the radical position taken by proponents of extreme
programming (XP) to get rid of 'unnecessary' documentation."

To which you have to ask, "Why would you want to write unnecessary
documentation? surely you have better things to do, like write necessary
documentation?".

A more productive debate would not be about the false dichotomy of
comments vs no-comments but about what comments should be for and what
level is 'necessary' and what level is 'sufficient'.

Personally I don't document algorithms (unless they are particularly
obscure) but I try to documemt the responsibility of a classes/modules
and the intent of methods (unless theyy are so well named it is
obvious). Generally I find that this is sufficient; furthermore
responsibilty and intent change slowly enough that the documentation
doesn't drift out of line with the code.

Tom

Tim Hunter wrote:
> Even if this is not directly about Ruby, both Jeff Raskin and the
> subject have come up before on this n.g. so I believe it's not
> altogether off-topic...
>
> Comments Are More Important Than Code
>
> http://acmqueue.com/modules.php?name=Content&pa=showpage&a...

Stephen Kellett

4/27/2005 3:50:00 PM

0

In message <d4o6vp$qj2$4@newsg2.svr.pol.co.uk>, Tom Ayerst
<twa@post.com> writes
>"I discard the radical position taken by proponents of extreme
>programming (XP) to get rid of 'unnecessary' documentation."
>
>To which you have to ask, "Why would you want to write unnecessary
>documentation? surely you have better things to do, like write
>necessary documentation?".

That is a straw man, removing the quotes around the word unnecessary to
change the meaning. Clearly Raskin doesn't agree that it is unnecessary,
if he did he wouldn't have put the word in quotes.

I agree with your comment about "what comments are for".

Stephen
--
Stephen Kellett
Object Media Limited http://www.objmedia.d...
RSI Information: http://www.objmedia.d.../rsi.html

Thomas Sondergaard

4/27/2005 4:45:00 PM

0

Jim Menard wrote:

> I don't know the answer; nobody on the Squeak mailing list has yet
> responded to my query about whether the code should be changed or the
> comment.

Presumably less code would break if the comment is changed rather than
the implementation.

Tom Ayerst

4/27/2005 6:08:00 PM

0

Stephen Kellett wrote:
> In message <d4o6vp$qj2$4@newsg2.svr.pol.co.uk>, Tom Ayerst
> <twa@post.com> writes
>
>> "I discard the radical position taken by proponents of extreme
>> programming (XP) to get rid of 'unnecessary' documentation."
>>
>> To which you have to ask, "Why would you want to write unnecessary
>> documentation? surely you have better things to do, like write
>> necessary documentation?".
>
>
> That is a straw man, removing the quotes around the word unnecessary to
> change the meaning. Clearly Raskin doesn't agree that it is unnecessary,
> if he did he wouldn't have put the word in quotes.
>

Kind of, but Raskin was distorting the XP position by putting the quotes
in in the first place. The XP position really is, "get rid of
unnecessary documentation", which is quite sensible (huge amounts of
documentation _is_ just written and never read, or left to get
pathologically out of date. By putting the quotes in, Raskin was trying
to suggest that their definition of uneccessary was wrong, which is a
quite legitimate debate to have, as I said further down. But by being
unable to resist having a poke at a methodology he doesn't like he moved
the argument to a "do comment"/"don't comment" level. Which was my point.

> I agree with your comment about "what comments are for".

Thanks, it works for me.

>
> Stephen

WoNáDo

4/27/2005 6:21:00 PM

0

"Tim Hunter" <sastph@sas.com> schrieb im Newsbeitrag news:d4o1i0$bd3$1@license1.unx.sas.com...
> Even if this is not directly about Ruby, both Jeff Raskin and the
> subject have come up before on this n.g. so I believe it's not
> altogether off-topic...
>
> Comments Are More Important Than Code
>
> http://acmqueue.com/modules.php?name=Content&pa=showpage&a...
--
Comments and everything like represent the "requirements", code is - in principle - nothing else than the
concrete realization. It may sound strange but the user (probably not the programmer) is interested in
requirement.

Wolfgang Nádasi-Donner
wonado@donnerweb.de


Dave Fayram

4/27/2005 6:27:00 PM

0

I actually sat down and read this artcile. I'm blown away by some of
the things he said. I'm so blown away that I am going to rant a little.
I hope no one minds. <:)

For example:
> Any language or system that does not allow full flowing and
> arbitrarily long comments is seriously behind the times. That
> we use escape characters to "escape" from code to comment is
> backwards. Ideally, comment should be the default, with a
> way to signal the occasional lines of code.


What he said up there, that's crazy talk. Ramblings about Literate
Programming aside, the idea that documentation should come before code
is a serious mistake. Documentation exists to *document code*, code
does not exist to follow documentation.

Then he rambles about "bad" comments and makes some trivial examples.
Then he puts in an example which he asserts is good, but doesn't really
justify why it's good to explain your algorithm choice in the code.
It's not unreasonable to name algorithms or patterns in your code, but
the "why" has no place in there, because that "why" is subject to
change and is outside the scope of the program itself.

If you want to explain why you did something, that's what a whitepaper
or tech memo is for. Your code isn't the place to justify your position
post facto. The fact that the code works should be justification
enough. :)

Inevitably, the documentation-heavy approach (comment-driven
development) leads to a design-up-front methodology. And I think we
have a mountain of evidence that the Waterfall Method and similar
up-front design methodologies are impractical at best.

I'm a big fan of documentation and code that lends itself to the
reader, and Ruby helps me with this, but my feeling is that if your
methods are so long that they require comments, then your methods are
too long. Sure, there are exceptions to this (explaining a tricky step,
saying why a non-obvious piece of code exists, naming a pattern or
algorithm), but in general I think this is a reaction to bad coding
practice.

I really like the Ruby communitiy's approach to documentation. Document
*what* functions do, give examples of class usage, provide rich unit
tests. But seldom do I see a project give step-by-step comments,
explain what variables are (beyond their name), or explain motiviations
in the code. This means we have beautiful Rdoc outputs and clean code.

Strictly speaking, the Rails documentation would fail this guy's
criterion for good documentation. But I think pretty much anyone who's
used Rails (and gotten past the awkward, "Where do I start" step) can
testify that the Rails documentation is complete and well-done.