Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   multiline comments (http://www.velocityreviews.com/forums/t356775-multiline-comments.html)

Edward Elliott 04-18-2006 11:53 PM

multiline comments
 
At the risk of flogging a dead horse, I'm wondering why Python doesn't have
any multiline comments. One can abuse triple-quotes for that purpose, but
that's obviously not what it's for and doesn't nest properly. ML has a
very elegant system for nested comments with (* and *).

Using an editor to throw #s in front of every line has limitations. Your
editor has to support it and you have to know how to use that feature. Not
exactly intuitive or easy for novices to pick up. Also a pain if your
preferred editor is python/perl/sh-agnostic.

Saying coders shouldn't use multiline comments to disable code misses the
point. Coders will comment out code regardless of the existence of
multiline comemnts. There has to be a better argument for leaving them out.

Keeping the language small and simple is desirable, but it's not an
absolute. A little syntactic sugar like 'for x in s' makes code easier to
read than 'for i in len(s): x = s[i]'. So what are the tradeoffs involved
with nested multiline comments? I'd like to understand the reasoning
behind keeping them out.

James Stroud 04-19-2006 04:33 AM

Re: multiline comments
 
Edward Elliott wrote:
> At the risk of flogging a dead horse, I'm wondering why Python doesn't
> have any multiline comments. One can abuse triple-quotes for that
> purpose, but that's obviously not what it's for and doesn't nest
> properly. ML has a very elegant system for nested comments with (* and *).
>
> Using an editor to throw #s in front of every line has limitations.
> Your editor has to support it and you have to know how to use that
> feature. Not exactly intuitive or easy for novices to pick up. Also a
> pain if your preferred editor is python/perl/sh-agnostic.
>
> Saying coders shouldn't use multiline comments to disable code misses
> the point. Coders will comment out code regardless of the existence of
> multiline comemnts. There has to be a better argument for leaving them
> out.
>
> Keeping the language small and simple is desirable, but it's not an
> absolute. A little syntactic sugar like 'for x in s' makes code easier
> to read than 'for i in len(s): x = s[i]'. So what are the tradeoffs
> involved with nested multiline comments? I'd like to understand the
> reasoning behind keeping them out.


I think the absence of multiline comments is like the requirement for
indentation. It enforces good habits. Better is to make your multiple
lines a function and comment out the function call.

James

--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/

Ben Finney 04-19-2006 05:10 AM

Re: multiline comments
 
James Stroud <jstroud@ucla.edu> writes:

> Edward Elliott wrote:
> > At the risk of flogging a dead horse, I'm wondering why Python
> > doesn't have any multiline comments. [...]
> >
> > Using an editor to throw #s in front of every line has
> > limitations. Your editor has to support it and you have to know
> > how to use that feature. Not exactly intuitive or easy for
> > novices to pick up. Also a pain if your preferred editor is
> > python/perl/sh-agnostic.

>
> I think the absence of multiline comments is like the requirement
> for indentation. It enforces good habits. Better is to make your
> multiple lines a function and comment out the function call.


And/or switch to an editor that can perform editing operations on a
range of lines.

--
\ Q: "I've heard that Linux causes cancer..." Torvalds: "That's |
`\ a filthy lie. Besides, it was only in rats and has not been |
_o__) reproduced in humans." -- Linus Torvalds |
Ben Finney


Atanas Banov 04-19-2006 05:41 AM

Re: multiline comments
 

Edward Elliott wrote:
> At the risk of flogging a dead horse, I'm wondering why Python doesn't have
> any multiline comments. One can abuse triple-quotes for that purpose, but
> that's obviously not what it's for and doesn't nest properly.

....
> Saying coders shouldn't use multiline comments to disable code misses the
> point. Coders will comment out code regardless of the existence of
> multiline comemnts. There has to be a better argument for leaving them out.


i beg to differ: you'd be surprised how much effect can little
inconveniences have.

want to comment block of code? use tripple-quotes. does not nest? ahhh,
maybe it's time to get rid of that block you commented out a month ago
"just in case the new code doesnt work".

that gives you incentive to tidy up. don't be a code slob... don't
leave a mess forever ;-)


Ben Finney 04-19-2006 06:02 AM

Re: multiline comments
 
"Atanas Banov" <enterr@gmail.com> writes:

> Edward Elliott wrote:
> > Saying coders shouldn't use multiline comments to disable code
> > misses the point. Coders will comment out code regardless of the
> > existence of multiline comemnts. There has to be a better
> > argument for leaving them out.

>
> i beg to differ: you'd be surprised how much effect can little
> inconveniences have.
>
> want to comment block of code? use tripple-quotes. does not nest?
> ahhh, maybe it's time to get rid of that block you commented out a
> month ago "just in case the new code doesnt work".


Indeed. Using revision control means never needing to comment out
blocks of code.

If your revision control system is so inconvenient to use that you'd
rather have large blocks of commented-out code, it's time to start
using a better RCS -- perhaps a distributed one, so you can commit to
your own local repository with abandon while trying out changes.

--
\ "I saw a sign: 'Rest Area 25 Miles'. That's pretty big. Some |
`\ people must be really tired." -- Steven Wright |
_o__) |
Ben Finney


Edward Elliott 04-19-2006 06:15 AM

Re: multiline comments
 
Atanas Banov wrote:
> want to comment block of code? use tripple-quotes. does not nest? ahhh,
> maybe it's time to get rid of that block you commented out a month ago
> "just in case the new code doesnt work".
>
> that gives you incentive to tidy up. don't be a code slob... don't
> leave a mess forever ;-)


And when the section I want to comment out contains a legit doc string in
the middle, triple-quotes won't work. There are valid reasons to nest
comments which have nothing to do with laziness or sloppy code.

Forcing programmers to write clean code with syntax is like teaching a pig
to sing: it wastes your time and annoys the pig. Good coding is a state of
mind, not a parser option.

Edward Elliott 04-19-2006 06:24 AM

Re: multiline comments
 
Ben Finney wrote:
> And/or switch to an editor that can perform editing operations on a
> range of lines.


I'm not unsympathetic to this point of view, as I would feel hamstrung
without my vim. It's more that I object to the paternalism of telling
people they have to use such an editor. There are times when notepad is
all that's available.

On top of that, the expressive power of nested comments seems greater than
an endless string of ^#s. Sometimes it's just easier to see what's going on.

Edward Elliott 04-19-2006 06:34 AM

Re: multiline comments
 
Ben Finney wrote:
> Indeed. Using revision control means never needing to comment out
> blocks of code.


Typing (* and *) on a few line will always be quicker, easier, and less
confusing than any rcs diffs/restores. Once you delete the code you can no
longer see it or add pieces back in without retrieving it from an external
store. I'm not saying nested comments solve every problem, just that there
exists a certain (perhaps small) class of problems they solve particularly
well.

Personally, I rarely leave code commented out beyond a single coding
session. But my particular coding habits aren't relevant here.

Lawrence D'Oliveiro 04-19-2006 07:12 AM

Re: multiline comments
 
In article <wZe1g.72406$dW3.16444@newssvr21.news.prodigy.com> ,
Edward Elliott <nobody@127.0.0.1> wrote:

>ML has a
>very elegant system for nested comments with (* and *).


Which, if you mistype an opening or closing comment symbol, can lead to
some very mysterious syntax errors.

Duncan Booth 04-19-2006 07:45 AM

Re: multiline comments
 
Edward Elliott wrote:

> Ben Finney wrote:
>> Indeed. Using revision control means never needing to comment out
>> blocks of code.

>
> Typing (* and *) on a few line will always be quicker, easier, and
> less confusing than any rcs diffs/restores. Once you delete the code
> you can no longer see it or add pieces back in without retrieving it
> from an external store. I'm not saying nested comments solve every
> problem, just that there exists a certain (perhaps small) class of
> problems they solve particularly well.


Would you care to name a few languages which support nested block
comments? There really aren't many: ML as you mentioned; Standard Pascal
doesn't permit nesting of comments but *some* implementations do allow it.

Want to comment out a block of code in C++? The only (nearly) reliable way
is to insert single-line comments down the block. You can't use a block
comment if there are any other block comments inside the code you want to
block out.

The danger of block comments is that if you forget to close the comment
you can accidentally comment out a large part of your code. With support
from the editor (coloured highlighting of comments) this isn't so bad,
but then if you have a decent editor you don't need the block comments
anyway as you will be able to comment/uncomment a block in your editor.

Doc strings will usually work as an alternative, especially since you
have a choice of two flavours of triple quoted strings, so if you use
one for docstrings the other is always free for your temporary block
comments.

> Forcing programmers to write clean code with syntax is like teaching a
> pig to sing: it wastes your time and annoys the pig.


This pig gets much more annoyed having to maintain code which has large
chunks of unneeded commented out code left over from some other programmer,
or which has completely messed up indentation.


All times are GMT. The time now is 02:45 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.