[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.python

What's the word on using """ to comment-out?

kj

2/24/2010 6:18:00 PM




I think I remember, early in my learning of Python, coming across
the commandment "THOU SHALT NOT USE TRIPLE-QUOTES TO COMMENT-OUT
LINES OF CODE", or something to that effect. But now I can't find
it!

Is my memory playing me a trick?

After all, from what I've seen since then, the practice of
triple-quote-commenting (or TQC, pardon the TCA) is in fact quite
common.

Is TQC OK after all?

If not, what's the case against it?

Also, has the BDFL expressed an opinion on the subject? Alternatively,
is there any other more or less "authoritative" opinion on TQC?

TIA!

~K

P.S. I can think of at least one reason to avoid TQC: it has
basically the same problems with nesting that C's /**/ has. (Sure,
in the case of TQC one could use "the other" triple quote, but it's
not hard to see that this workaround goes only so far.) But this
reason does not seem to bother many programmers, most of whom,
after all, cut their teeth with C and /**/.

P.S.2 I'm disregarding "it's un-Pythonic" as a reason against TQC,
because it's not the kind of reason that carries much weight out
here "in the trenches", as I've discovered. But, yes, I happen to
think that TQC is un-Pythonic. After all, in my programming
environment, it takes half as many keystrokes to comment a block
of code with # than it does with """. I imagine that any decent
programming environment makes #-commenting at least as easy.
Therefore, there goes convenience as an argument in defense of TQC.
Which leaves TMTOWTDI as the only possible defense for TQC, and
TMTOWTDI is pretty un-Pythonic, no? :)
14 Answers

rantingrick

2/24/2010 7:04:00 PM

0

On Feb 24, 12:18 pm, kj <no.em...@please.post> wrote:
> I think I remember, early in my learning of Python, coming across
> the commandment "THOU SHALT NOT USE TRIPLE-QUOTES TO COMMENT-OUT
> LINES OF CODE", or something to that effect.  But now I can't find
> it!

Your going to get many opinions on this subject but my stance is --
use quotes for stings and hash chars for comments -- thats the end of
it for me ;)

mk

2/24/2010 7:12:00 PM

0


Get a decent editor, like PyScripter, and press Ctrl-' (toggle comment).

Regards,
mk


mk

2/24/2010 7:12:00 PM

0


Get a decent editor, like PyScripter, and press Ctrl-' (toggle comment).

Regards,
mk



aahz

2/24/2010 7:28:00 PM

0

In article <hm3qhi$2cd$1@reader2.panix.com>, kj <no.email@please.post> wrote:
>
>I think I remember, early in my learning of Python, coming across the
>commandment "THOU SHALT NOT USE TRIPLE-QUOTES TO COMMENT-OUT LINES OF
>CODE", or something to that effect. But now I can't find it!
>
>Is my memory playing me a trick?

Possibly. I certainly do that.
--
Aahz (aahz@pythoncraft.com) <*> http://www.python...

"Many customs in this life persist because they ease friction and promote
productivity as a result of universal agreement, and whether they are
precisely the optimal choices is much less important." --Henry Spencer

CM

2/24/2010 10:41:00 PM

0

> After all, from what I've seen since then, the practice of
> triple-quote-commenting (or TQC, pardon the TCA) is in fact quite
> common.
>
> Is TQC OK after all?
>
> If not, what's the case against it?

I have no sense of how approved it is, and don't have a strong opinion
on it, but I would think that some cases against it could be:

- It's used for docstrings, so when you scan code it is harder to
instantly find comment blocks or docstrings if IDE parsers color code
comments differently than docstrings. An IDE I use (Boa Constructor)
uses "# XXX [comment]" as a comment that means "add to the to-do list"
as well.

- If you want to search for comments easily, you can search for #,
which will probably only bring you to comments, whereas if you search
for quote marks, they could be used in a number of different ways in
the code.

- Adhering to coding conventions is a good thing in open source
applications.


Steven D'Aprano

2/25/2010 12:51:00 AM

0

On Wed, 24 Feb 2010 18:18:27 +0000, kj wrote:

> I think I remember, early in my learning of Python, coming across the
> commandment "THOU SHALT NOT USE TRIPLE-QUOTES TO COMMENT-OUT LINES OF
> CODE", or something to that effect. But now I can't find it!
>
> Is my memory playing me a trick?
>
> After all, from what I've seen since then, the practice of
> triple-quote-commenting (or TQC, pardon the TCA) is in fact quite
> common.

Oooh, I hope not... for anything but Q&D scripting, folks should be using
source control rather than filling their source code up with vast lumps
of old dead code.


> Is TQC OK after all?

Only if you're lazy and slack, and being lazy and slack is itself only
okay if you are only lazy and slack *a very little bit*. In a small
script, using test-driven development, it is acceptable to comment out
dead code for a single test run. At the end of the run, you either
reverse the commenting out, or you delete the dead code.


> If not, what's the case against it?

Commenting out dead code is, itself, a BAD THING, regardless of whether
you use comments or triple-quotes.

http://www.coderenaissance.com/2008/09/quit-commenting-out-dead...


Triple-quoted comments are worrying, though, because the result of them
is not specified by the language. (Other than docstrings, of course.) The
CPython compiler optimizes them away at compile time, so they have no
runtime influence at all, but other implementations may not include this
optimization and so the string gets compiled into the byte-code, created
at runtime, then immediately deleted. Ouch.



--
Steven

Paul Rudin

2/25/2010 7:56:00 AM

0

kj <no.email@please.post> writes:

> I think I remember, early in my learning of Python, coming across
> the commandment "THOU SHALT NOT USE TRIPLE-QUOTES TO COMMENT-OUT
> LINES OF CODE", or something to that effect. But now I can't find
> it!

No idea, but it would be nice to have some multiline comment syntax
(other than # at the beginning of each line). Particularly one that can
be nested.

Tim Chase

2/25/2010 10:45:00 AM

0

Paul Rudin wrote:
> kj <no.email@please.post> writes:
>
>> I think I remember, early in my learning of Python, coming across
>> the commandment "THOU SHALT NOT USE TRIPLE-QUOTES TO COMMENT-OUT
>> LINES OF CODE", or something to that effect. But now I can't find
>> it!
>
> No idea, but it would be nice to have some multiline comment syntax
> (other than # at the beginning of each line). Particularly one that can
> be nested.

Well, there's always "if 0"/"if False", but that requires
screwing with the indentation levels. Granted, any competent
text editor will allow you to easily shift code indentation (I
know Vim does, and am pretty sure Emacs will let you do the
same...YMMV with other editors).

But yes, there have been times that a multi-line commenting that
doesn't touch your indentation would be nice, and I confess to
using triple-quotes to do that (opting for """ or ''' based on
the type of triple-quotes found in the code). However, I usually
limit this for debugging purposes and they usually get pruned or
uncommented for production code.

-tkc



Lie Ryan

2/25/2010 12:51:00 PM

0

On 02/25/10 05:18, kj wrote:
> I think I remember, early in my learning of Python, coming across
> the commandment "THOU SHALT NOT USE TRIPLE-QUOTES TO COMMENT-OUT
> LINES OF CODE", or something to that effect. But now I can't find
> it!

I've never heard of it, though I can think of a few reasons why TQC
might be a bad thing. Especially if a user pydoc-ed your module and see
a bunch of meaningless code.

> Is my memory playing me a trick?
>
> After all, from what I've seen since then, the practice of
> triple-quote-commenting (or TQC, pardon the TCA) is in fact quite
> common.
>
> Is TQC OK after all?

I'd say it's OK for quick and dirty code, or when you're rewriting a
significant part of the code especially in early development (or you
haven't setup a version control system since it's a damn small script).
They shouldn't be permanent though, due to docstring problem.

> If not, what's the case against it?
>
> Also, has the BDFL expressed an opinion on the subject? Alternatively,
> is there any other more or less "authoritative" opinion on TQC?

Dave \Crash\ Dummy

2/25/2010 3:07:00 PM

0

On 2010-02-25, Paul Rudin <paul.nospam@rudin.co.uk> wrote:
> kj <no.email@please.post> writes:
>
>> I think I remember, early in my learning of Python, coming across
>> the commandment "THOU SHALT NOT USE TRIPLE-QUOTES TO COMMENT-OUT
>> LINES OF CODE", or something to that effect. But now I can't find
>> it!
>
> No idea, but it would be nice to have some multiline comment syntax
> (other than # at the beginning of each line). Particularly one that can
> be nested.

if 0:

Seriously, that's what I generally do: mark the block of code,
indent it 1 level, add an if 0: at the top.

--
Grant Edwards grante Yow! What a COINCIDENCE!
at I'm an authorized "SNOOTS
visi.com OF THE STARS" dealer!!