[Python-Dev] Can we triple quoted string as a comment?

2013-03-25 Thread Victor Stinner
Hi,

I just realized that the Python peephole optimizer removes useless
instructions like numbers and strings between other instructions,
without raising an error nor emiting an error. Example:

$ python -Wd -c 'print "Hello"; "World"'
Hello

As part of my astoptimizer project, I wrote a function to detect such
useless instructions which emit a warning. I opened the following
issue to report what I found:
http://bugs.python.org/issue17516

Different modules use long strings as comments. What is the "official"
policy about such strings? Should we use strings or comments?

(IMO a comment should be used instead.)

Victor
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Can we triple quoted string as a comment?

2013-03-25 Thread Gregory P. Smith
On Mon, Mar 25, 2013 at 2:16 PM, Victor Stinner wrote:

> Hi,
>
> I just realized that the Python peephole optimizer removes useless
> instructions like numbers and strings between other instructions,
> without raising an error nor emiting an error. Example:
>
> $ python -Wd -c 'print "Hello"; "World"'
> Hello
>
> As part of my astoptimizer project, I wrote a function to detect such
> useless instructions which emit a warning. I opened the following
> issue to report what I found:
> http://bugs.python.org/issue17516
>
> Different modules use long strings as comments. What is the "official"
> policy about such strings? Should we use strings or comments?
>

Comments.
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Can we triple quoted string as a comment?

2013-03-25 Thread Raymond Hettinger

On Mar 25, 2013, at 2:16 PM, Victor Stinner  wrote:

> Hi,
> 
> I just realized that the Python peephole optimizer removes useless
> instructions like numbers and strings between other instructions,
> without raising an error nor emiting an error. Example:
> 
> $ python -Wd -c 'print "Hello"; "World"'
> Hello

IIRC, this happens upstream from the peephole optimizer
and has been a part of Python for a long time.

You can also "comment-out" code with "if 0:"

>>> def f(x):
if 0:
print x
return x+1

>>> from dis import dis
>>> dis(f)
  4   0 LOAD_FAST0 (x)
  3 LOAD_CONST   1 (1)
  6 BINARY_ADD  
  7 RETURN_VALUE 

> 
> As part of my astoptimizer project, I wrote a function to detect such
> useless instructions which emit a warning. I opened the following
> issue to report what I found:
> http://bugs.python.org/issue17516

Make sure it is a warning you can turn-off.

I've seen code in many organizations that use multi-line
strings to "turn-off" a section of code but not actually remove the code
from the source.


> 
> Different modules use long strings as comments. What is the "official"
> policy about such strings? Should we use strings or comments?
> 
> (IMO a comment should be used instead.)

The module authors typically make their own decisions
with respect to readability and ease of commenting.

If you're editing with Emacs, it is really easy to reflow paragraphs
and to insert or remove multiline comments each prefixed with #.
But with other editors, it can be a PITA and a multiline string is
the easiest to maintain and works well when cutting-and-pasting
the comments from somewhere else.

I worry that because you just discovered this feature, the initial
reaction is that is a horribly wrong thing to do and should be
"fixed" everywhere.

Instead, it would be better to live-and-let live.
No need for wholesale code changes or imposition
"you must do it the way I do it" policies.


my-two-cents,


Raymond___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Can we triple quoted string as a comment?

2013-03-26 Thread R. David Murray
On Mon, 25 Mar 2013 18:16:47 -0700, Raymond Hettinger 
 wrote:
> If you're editing with Emacs, it is really easy to reflow paragraphs
> and to insert or remove multiline comments each prefixed with #.
> But with other editors, it can be a PITA and a multiline string is
> the easiest to maintain and works well when cutting-and-pasting
> the comments from somewhere else.

Just FYI it is also very easy in vim: gq plus whatever movement prefix
suits the situation.

--David
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Can we triple quoted string as a comment?

2013-03-26 Thread Antoine Pitrou
Le Tue, 26 Mar 2013 09:28:51 -0400,
"R. David Murray"  a écrit :
> On Mon, 25 Mar 2013 18:16:47 -0700, Raymond Hettinger
>  wrote:
> > If you're editing with Emacs, it is really easy to reflow paragraphs
> > and to insert or remove multiline comments each prefixed with #.
> > But with other editors, it can be a PITA and a multiline string is
> > the easiest to maintain and works well when cutting-and-pasting
> > the comments from somewhere else.
> 
> Just FYI it is also very easy in vim: gq plus whatever movement prefix
> suits the situation.

And on a user-friendly editor such as Kate, you can press Ctrl+D.

Regards

Antoine.


___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Can we triple quoted string as a comment?

2013-03-26 Thread Ethan Furman

On 03/25/2013 02:16 PM, Victor Stinner wrote:

Hi,

I just realized that the Python peephole optimizer removes useless
instructions like numbers and strings between other instructions,
without raising an error nor emiting an error. Example:

$ python -Wd -c 'print "Hello"; "World"'
Hello

As part of my astoptimizer project, I wrote a function to detect such
useless instructions which emit a warning. I opened the following
issue to report what I found:
http://bugs.python.org/issue17516

Different modules use long strings as comments. What is the "official"
policy about such strings? Should we use strings or comments?

(IMO a comment should be used instead.)


Someone will correct me if I'm wrong, I'm sure, but I believe Guido himself has said that a neat feature of 
triple-quoted strings is their ability to be used as comments.


--
~Ethan~
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Can we triple quoted string as a comment?

2013-03-26 Thread Guido van Rossum
And I still think it's neat. :-)


On Tue, Mar 26, 2013 at 8:46 AM, Ethan Furman  wrote:

> On 03/25/2013 02:16 PM, Victor Stinner wrote:
>
>> Hi,
>>
>> I just realized that the Python peephole optimizer removes useless
>> instructions like numbers and strings between other instructions,
>> without raising an error nor emiting an error. Example:
>>
>> $ python -Wd -c 'print "Hello"; "World"'
>> Hello
>>
>> As part of my astoptimizer project, I wrote a function to detect such
>> useless instructions which emit a warning. I opened the following
>> issue to report what I found:
>> http://bugs.python.org/**issue17516 
>>
>> Different modules use long strings as comments. What is the "official"
>> policy about such strings? Should we use strings or comments?
>>
>> (IMO a comment should be used instead.)
>>
>
> Someone will correct me if I'm wrong, I'm sure, but I believe Guido
> himself has said that a neat feature of triple-quoted strings is their
> ability to be used as comments.
>
> --
> ~Ethan~
>
> __**_
> Python-Dev mailing list
> Python-Dev@python.org
> http://mail.python.org/**mailman/listinfo/python-dev
> Unsubscribe: http://mail.python.org/**mailman/options/python-dev/**
> guido%40python.org
>



-- 
--Guido van Rossum (python.org/~guido)
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Can we triple quoted string as a comment?

2013-03-28 Thread Xavier de Gaye
On Tue, Mar 26, 2013 at 2:28 PM, R. David Murray wrote:
> On Mon, 25 Mar 2013 18:16:47 -0700, Raymond Hettinger wrote:
>> If you're editing with Emacs, it is really easy to reflow paragraphs
>> and to insert or remove multiline comments each prefixed with #.
>> But with other editors, it can be a PITA and a multiline string is
>> the easiest to maintain and works well when cutting-and-pasting
>> the comments from somewhere else.
>
> Just FYI it is also very easy in vim: gq plus whatever movement prefix
> suits the situation.

And to comment out multiple lines in vim, each prefixed with #, see
":help v_b_I" and ":help v_b_I_example".

Xavier
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com