Single Pound # comments versus Double Pound ## comments 
Author Message
 Single Pound # comments versus Double Pound ## comments

In python code, does anyone distinguish between starting comments with
a single pound (#) or a double pound (##)?
ActivePython colorizes them differently (# - green, ## - gray), and
not understanding the distinction implied is bugging me.


Wed, 23 Mar 2005 03:12:11 GMT  
 Single Pound # comments versus Double Pound ## comments
Technically, there is no difference.  A comment is a comment.
Practically, double pounds are used to comment out sections of code.
Showing them in gray makes commented out code easier to ignore.
Regular comments are meant to be read, so they show-up in green.

Raymond Hettinger



Quote:
> In Python code, does anyone distinguish between starting comments with
> a single pound (#) or a double pound (##)?
> ActivePython colorizes them differently (# - green, ## - gray), and
> not understanding the distinction implied is bugging me.



Wed, 23 Mar 2005 03:37:06 GMT  
 Single Pound # comments versus Double Pound ## comments

Quote:
> In Python code, does anyone distinguish between starting comments with
> a single pound (#) or a double pound (##)?
> ActivePython colorizes them differently (# - green, ## - gray), and
> not understanding the distinction implied is bugging me.

My guess is it sees ## as "I am commenting out this block of code
temporarily".  I have also seen people use ## for block comments above a
function or tricky piece of code.


Wed, 23 Mar 2005 03:34:51 GMT  
 Single Pound # comments versus Double Pound ## comments
[Manuel M. Garcia]

Quote:
> In Python code, does anyone distinguish between starting comments with
> a single pound (#) or a double pound (##)?

I introduced two conventions of this nature in the early days of the Emacs
Python mode:  ## was used by the comment-region command to "comment out" a
contiguous block of code.  Many others have done likewise.  In addition,
Python mode makes a distinction between "indenting comment lines" and
"non-indenting comment lines".  If a line starting with # has whitespace
immediately following, and you hit ENTER/RETURN, Python mode reproduces its
indentation on the new line; if it doesn't have whitespace immediately
following (like '##' or '#...'), then its indentation is ignored, and Python
mode looks backwards for the closest-preceding statement to mimic.

Quote:
> ActivePython colorizes them differently (# - green, ## - gray), and
> not understanding the distinction implied is bugging me.

I expect they're just following the convention that # means "this is a
useful comment" and ## means "this section is commented out -- pretend it
doesn't even exist".


Wed, 23 Mar 2005 04:14:40 GMT  
 Single Pound # comments versus Double Pound ## comments

Quote:

> In Python code, does anyone distinguish between starting comments with
> a single pound (#) or a double pound (##)?
> ActivePython colorizes them differently (# - green, ## - gray), and
> not understanding the distinction implied is bugging me.

When using python-mode for Emacs, if you elect to "Comment Region"
then double-pound signs are inserted.  If you elect to "Uncomment
Region" then only those lines beginning with a double-pound are
uncommented.  So perhaps the lines are highlighted differently on the
assumption that double-pound lines contain "disabled" code.

--
Mitch Chapman



Wed, 23 Mar 2005 05:49:26 GMT  
 Single Pound # comments versus Double Pound ## comments

Quote:
> [Manuel M. Garcia]
> > In Python code, does anyone distinguish between
> starting comments with
> > a single pound (#) or a double pound (##)?

> I expect they're just following the convention that #
> means "this is a
> useful comment" and ## means "this section is commented
> out -- pretend it
> doesn't even exist".

I'd like to add that in Zope, when you store Python scripts
on the file system, the meta-data (arguments expected,
namespace bindings, etc) is stored in a block of double-commented
"##" text at the top of the file. These comments are interpreted
by Zope and are stripped out of the imported file.  I can't
comment on whether this is wise design or not, but that's
how they do it.

It occurs to me, in reference to a previous thread about
blocked-comments, rather than line comments, that having
blocks like:

###
  This might be a block comment in some hypothetical
  future version of Python. Although I'm not holding
  my breath.
###

Might be very sensible, analogous to the """ string
definitions.  Since someone pointed out that unused
strings are stripped out, unless they correspond to
docstrings or something, this would have very similar
semantics. Except that it could be more unambiguous --
such as being used to block out code even within
expressions:

this_is_a_dict = {
                   'spam':1,
###
Didn't really want this part, but might later:

                   'ham':3,
                   'eggs':4,
###
                   'morespam':2
                 }

The nice thing being that you don't have to muddle up
the indentation or edit every single line in the section
you wanted to comment out (or depend on editor gymnastics
to accomplish this for you).

It also seems like this would be moderately easy to
implement, since """ is already caught.  The only
semantic difference would be that ### is always thrown
out (I think this is true anyway).

Despite seeing discussion about block comments on
list, I can't find anything in the PEPs. Am I
looking in the wrong place, or did it just not ever
get that far? Would there be a "sure, send us a patch
cause we don't want to do it" or a "Aaauurrghh! Get
that away from me!" sort of response to this sort
of thing, do you think?

If it's the former, I might have a look at the sources
and see if it's really as simple as I think it must
be.

Cheers,
Terry

--
------------------------------------------------------
Terry Hancock

Anansi Spaceworks                
http://www.anansispaceworks.com
P.O. Box 60583                    
Pasadena, CA 91116-6583
------------------------------------------------------



Wed, 23 Mar 2005 07:04:00 GMT  
 Single Pound # comments versus Double Pound ## comments
Quote:

> ###
>   This might be a block comment in some hypothetical
>   future version of Python. Although I'm not holding
>   my breath.
> ###

> Might be very sensible, analogous to the """ string
> definitions.
[...]
> Except that it could be more unambiguous --
> such as being used to block out code even within
> expressions:

> this_is_a_dict = {
>                    'spam':1,
> ###

  # Didn't really want this part, but might later:

Quote:

>                    'ham':3,
>                    'eggs':4,
> ###
>                    'morespam':2
>                  }

How is this "more unambiguous", given that the code fragment above has a
meaning today?

Jeff



Wed, 23 Mar 2005 07:10:35 GMT  
 Single Pound # comments versus Double Pound ## comments

Quote:

> It also seems like this would be moderately easy to
> implement, since """ is already caught.  The only
> semantic difference would be that ### is always thrown
> out (I think this is true anyway).

I personally use ### as a FIXME comment, so I'll know to get back to it
at some point.  Either way, constructs that are not backward compatible,
such as using ###...### for a multiline quote, seem like a really bad
idea at this point.

--

 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ The people are to be taken in very small doses.
\__/ Ralph Waldo Emerson
    The laws list / http://www.alcyone.com/max/physics/laws/
 Laws, rules, principles, effects, paradoxes, etc. in physics.



Wed, 23 Mar 2005 08:25:36 GMT  
 Single Pound # comments versus Double Pound ## comments

Quote:

> Seems to me the "###" would currently just get thrown out,
> leaving the dictionary unedited.  Clearly code that relied
> on this would be incompatible with earlier versions of the
> interpreter, but that's a different issue.

I think that is what was meant by it being ambiguous is that it would have
different (and not always easily separable behavior) on older python.  It is
a change of behavior for previously valid code.  Just how common it is to
have ### by itself on a source line, I don't know. :)

Quote:
> As it stands, if I want this behavior, I can only acheive
> it by editing every line:
> Which is not too bad for a two-line example, but can
> be quite obnoxious for testing larger pieces of code.

As you say, use a smarter editor; or use the "if 0:" idiom to comment out
blocks of code (again, an auto reindenting editor helps).

And, if  you say that "if 0:" won't work in this case, I say, "true".  You
could rewrite it as:

this_is_a_dict = {}
this_is_a_dict[ 'spam' ] = 1
this_is_a_dict[ 'ham' ] = 3
this_is_a_dict[ 'eggs' ] = 4
this_is_a_dict[ 'morespam' ] = 2

And then use the "if 0:" idiom.  Or auto-insert of comments.

Ah, but that is all work... Yes.  So, do the benfits outweigh the costs.
Hmmmm...  Well, I personally am not a big fan of using comments to disable
code; I guess I've seen WAY to much abuse of it at work and elsewhere.  And
my editor is more than capable, so perhaps others can weigh in on what it
would buy them.

--

Chad Netzer



Wed, 23 Mar 2005 08:14:57 GMT  
 Single Pound # comments versus Double Pound ## comments

Quote:

> And then use the "if 0:" idiom.  Or auto-insert of comments.

> Ah, but that is all work... Yes.  So, do the benfits outweigh the costs.
> Hmmmm...  Well, I personally am not a big fan of using comments to disable
> code; I guess I've seen WAY to much abuse of it at work and elsewhere.  And
> my editor is more than capable, so perhaps others can weigh in on what it
> would buy them.

I think this syndrome is common where there's either no revision control or
some programmers aren't familiar with the power of the systems.  The large
project I work on has had a heavily customized RCS setup for 3 years now,
but one old-time programmer still surrounds his changes with
    #if 1 /* so and so, this day, 2002 */
    .... new code ...
    #else
    .... old code ...
    #endif
.. and another saves copies of her changes with strange names like
'somefile.c-----this-date----bugreportnumber----changed-something' in case
she "needs to undo the changes".

Armed with rcs and ediff, this is largely unnecessary, since you can revert
the file to past versions, find commentary on each change, easily find
differences between the release & development trees, etc.

Hey, can I submit a patch to Python so that I can run
    python -rREV somescript.py
and run the named version of the script?  This would be great---by using a
symbolic tag, I could run any past version of the script.  Maybe by using
comma-separated tags I could specify a series of them to be tried for each
file until one passed:
    python -rmyproject_1_0,release22-maint myscript.py
this will use files from version 1.0 of my software and from the
release22-maint branch of Python.

Okay, okay, I'm just joking.  God, it's not like I was going to tell one of
those lame PSA jo



Wed, 23 Mar 2005 10:29:11 GMT  
 Single Pound # comments versus Double Pound ## comments


Quote:
> In Python code, does anyone distinguish between starting comments with
> a single pound (#) or a double pound (##)?
> ActivePython colorizes them differently (# - green, ## - gray), and
> not understanding the distinction implied is bugging me.

I'd just like to point out that it is PythonWin and not ActivePython that
does this.

-d



Wed, 23 Mar 2005 13:38:01 GMT  
 
 [ 14 post ] 

 Relevant Pages 

1. Five Pound of Sugar in a One Pound Sack ;-)

2. Pound delays in non-blocking assignments

3. the term "pound sign"

4. Pound Sign

5. Cobol Programmers needed, salaries 1500+ pounds

6. PalmTcl ready for pounding

7. Counting commented lines (full-line comments only)

8. comments on comments

9. meta-comments for comments on proposals

10. comments on comments

11. comments on comments

12. Non single-line comments?

 

 
Powered by phpBB® Forum Software