Can we triple quoted string as a comment?

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

On Mar 25, 2013, at 2:16 PM, Victor Stinner <victor.stinner@gmail.com> wrote:
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:"
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.
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

On Mar 25, 2013, at 2:16 PM, Victor Stinner <victor.stinner@gmail.com> wrote:
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:"
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.
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
participants (8)
-
Antoine Pitrou
-
Ethan Furman
-
Gregory P. Smith
-
Guido van Rossum
-
R. David Murray
-
Raymond Hettinger
-
Victor Stinner
-
Xavier de Gaye