commenting out blocks of code
Steve Holden
steve at holdenweb.com
Sat Feb 18 13:35:22 EST 2006
Steven D'Aprano wrote:
> On Fri, 17 Feb 2006 19:12:01 -0500, Peter Hansen wrote:
>
>
>>john peter wrote:
>>
>>>is there a similar mechanism in python, other than prefixing
>>>the '#' character to the start of each statement i do not
>>>want to execute (which gets old very quickly if one needs to
>>>comment and uncomment several statements a couple of
>>>times while "playing around with code" say during initial design)?
>>
>>In addition to the approach Paul has suggested, you should also consider
>>using a better editor, as most decent editors should have some kind of
>>"block comment/uncomment" feature that prevents that operation from
>>getting old very quickly...
>>
>>Scite, for example, lets me selected a block and hit Ctrl-Q to either
>>comment or uncomment the block.
>
>
> I see the developers of Scite are either newbies to GUI programming, or
> they operate in a world of their own. Ctrl-Q is reserved for Quit (or
> Exit) in every GUI API I know of.
>
I don't think this is common enough to regard as any kind of de facto
standard.
Just to give two further counterexamples, neither TextPad nor Notepad
action a Ctrl/Q in that way. Perhaps I'm just using the wrong operating
system?
>
>
>>(It does this by prefixing each line
>>with #~ instead of just #, which allows it to detect when a line is
>>already so commented and reverse the operation.)
>
>
> It is *easy* to detect when a line is already commented. It starts with a
> #. The ~ is superfluous.
>
> Commenting and uncommenting should be two different commands: the whole
> point of nested comments is that it allows you to comment a block of text
> which may already contain comments. Having one command do both commenting
> and uncommenting according to the presence or absence of semantic clues in
> the text is a recipe for failure ("No you stupid computer, I want to
> COMMENT that block, not uncomment it!!!").
>
> Imagine if your text editor used cntl-C for both copy and paste, somehow
> guessing whether you wanted to copy selected text or paste over it
> according to some subtle clue in the text itself. Wouldn't that be fun?
>
I agree that's a less-than-sensible feature implementation.
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/
More information about the Python-list
mailing list