Re: commenting out blocks of code

2006-02-19 Thread Peter Hansen
Steve Holden wrote:
 Steven D'Aprano wrote:
On Fri, 17 Feb 2006 19:12:01 -0500, Peter Hansen wrote:
Scite, for example, lets me selected a block and hit Ctrl-Q to either 
comment or uncomment the block.
(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.

I submit that Steve and Steven (neither of whom has apparently even 
*used* this feature of Scite before criticizing it so strongly), should 
consider whether in actual practice something like this might not be 
much more effective than they can apparently imagine.

I'm strongly critical of many features of most editors, and thus use 
very few of them, and I also happen to have a solid background in GUI 
design and ergonomics.  I'm also a heavy user of Scite, and have found 
it readily accepted amongst the groups of programmers with whom I've worked.

I and my team have found the Ctrl+Q feature of Scite to be very 
sensible, highly effective and useful, and in fact *better* than 
alternatives that we've used before in other editors.

Kudos to Neil for having the (apparently) unusual design sense to think 
of it and implement it!

So there.  Harumph.  :-)

-Peter

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: commenting out blocks of code

2006-02-19 Thread Neil Hodgson
Atanas Banov:

 here is something you both seems to have not considered: imagine you
 make decision if ^Q has to comment or uncomment based on the 1st line
 and not on each line individually in the block. 

   When first implementing Ctrl+Q, this looked to have similar
advantages and disadvantages to the chosen implementation. However, it
wouldn't allow a technique I've come to use which is to have two
versions of some code or section of a configuration file and to toggle
between the two by selecting the whole range and pressing Ctrl+Q.

 #code1
 ##comment1
 ##comment2
 #code2
 
 
 note how ## maintains where comments were. now, for the same selection,
 ^Q again? 1st character is #, so the editor is asked to uncomment,
 dwim:

   The problem with ## as opposed to #~ is that ## is common in
much source code particularly in barrier comments and comment sections:

 Persistence section 
## These functions are responsible for load
## and save for the core media database.

   Neil
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: commenting out blocks of code

2006-02-18 Thread Duncan Booth
Steven D'Aprano wrote:

 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.

Your experience obviously differs from mine. I just tried Ctrl-Q on both 
windows and ubuntu and in neither case did it exit applications 
consistently: For example Firefox uses Alt-F4 in both cases.

My own favourite editor (Epsilon) uses Ctrl-Q for the 'quoted-insert' 
command (hardly suprising given its similarity to emacs).

 (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.
 
Not so easy if the lines to be commented already contain some lines 
starting with comments. Messing around with the comments themselves sounds 
highly unsatisfactory though.

I agree with you that the best solution is to use different commands (or as 
Epsilon does a single command which can be modified with a prefix Ctrl-U). 
That way I can select a large region and comment it all out, or uncomment 
disjoint parts of it as I choose.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: commenting out blocks of code

2006-02-18 Thread Steven D'Aprano
On Sat, 18 Feb 2006 03:14:49 +, Neil Hodgson wrote:

 I am the developer responsible for SciTE and the Ctrl+Q decision.
 Ctrl+Q is not reserved for Quit on every platform. 

[snip]


Thank you for your thoughtful response. Although I'm not convinced by your
reasoning, I will concede that perhaps my post was a little hasty.


-- 
Steven.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: commenting out blocks of code

2006-02-18 Thread Steve Holden
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/

-- 
http://mail.python.org/mailman/listinfo/python-list


commenting out blocks of code

2006-02-17 Thread john peter
in java, i can prevent a block of code from executing  by bracketing the block with comment indicators, as shown  below:  /*   statement1 will not execute;   statement2 will not execute;  */   statement3 will executeis 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)?  
		 Yahoo! Autos. Looking for a sweet ride? Get pricing, reviews, & more on new and used cars.-- 
http://mail.python.org/mailman/listinfo/python-list

Re: commenting out blocks of code

2006-02-17 Thread Paul McNett
john peter wrote:
  in java, i can  prevent a block of code from executing
 by bracketing the block with comment indicators, as shown
 below:
 /*
   statement1 will not execute;
   statement2 will not execute;
 */
   statement3 will execute
 
 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)?

IMO this is a missing feature in Python. However, if the block of code 
you are wanting to comment out doesn't happen to contain any 
triple-quotes, you can surround the code with those. For example:

def myFunc(arg):
return arg + 2


def myFunc(arg):
return arg + 1


  print myFunc(2)
4


-- 
Paul


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: commenting out blocks of code

2006-02-17 Thread Peter Hansen
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.  (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.)  Other decent editors 
have their own approach.

-Peter

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: commenting out blocks of code

2006-02-17 Thread Steven D'Aprano
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.


 (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?



-- 
Steven.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: commenting out blocks of code

2006-02-17 Thread Jean-Paul Calderone
On Sat, 18 Feb 2006 12:36:06 +1100, Steven D'Aprano [EMAIL PROTECTED] wrote:
 [snip]

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?


emacs' comment-dwim (M-;) has never guessed incorrectly, in my experience.  Of 
course, if it ever does, I can always invoke comment-region or 
uncomment-region, as appropriate.



--
Steven.

--
http://mail.python.org/mailman/listinfo/python-list

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: commenting out blocks of code

2006-02-17 Thread Cameron Laird
In article [EMAIL PROTECTED],
Paul McNett  [EMAIL PROTECTED] wrote:
.
.
.
IMO this is a missing feature in Python. However, if the block of code 
you are wanting to comment out doesn't happen to contain any 
triple-quotes, you can surround the code with those. For example:

def myFunc(arg):
   return arg + 2


def myFunc(arg):
   return arg + 1


  print myFunc(2)
4
.
.
.
... and note that, even if the block *does* contain triple-quotes
of one flavor, you can use the other:

  '''This is syntactic data:  .

  '''
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: commenting out blocks of code

2006-02-17 Thread Neil Hodgson
Hi Steven,

 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 am the developer responsible for SciTE and the Ctrl+Q decision.
Ctrl+Q is not reserved for Quit on every platform. Perhaps you have
never used Windows where Exit does not normally have a distinct command 
key of its own but can be performed with Alt+F4 (Close) for single 
window applications. Since exiting an application is a far less common 
action than modifying the data within that application, it doesn't 
deserve one of the more easily typed key bindings. Some applications use 
Ctrl+Q but, of the applications I currently have open, Firefox, Internet 
Explorer, Explorer, iTunes, Visual Studio .NET, WordPad, QuickTime, 
PythonWin, and WinMerge don't respond to Ctrl+Q by quitting and 
Thunderbird does.
Windows guidelines:
http://msdn.microsoft.com/library/en-us/dnwue/html/appxB.asp

 It is *easy* to detect when a line is already commented. It starts with a
 #. The ~ is superfluous.

It is not usual to change a line from being code to being a comment 
as most lines of code make no sense as English text. If you do sometimes 
want to do this, the # key can be pressed at the beginning of a line. 
Ctrl+Q exists to allow commenting out sections of code that you do not 
want to be active. The ~ acts to differentiate these different uses of 
one language feature and makes it easy to apply the operation over
ranges that include comments and then invert the operation.

 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!!!).

Comments and commented out code are distinct. Using the same marker
for both is ambiguous. Few languages support true nested comments.

SciTE's implementation of Ctrl+Q is very popular although you can 
change the text inserted/removed from #~ to # if you prefer and 
SciTE also includes a command to add stream style comments for languages 
like /* C++ */.

 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?

Your imaginary command makes no sense as it is described. What are 
its full semantics? Why was it implemented this way?

BTW, I have been implementing GUIs for over 20 years so maybe me and
the other SciTE users are in our own world. It does feel like a
friendly, enjoyable, comfortable world, though.

Neil
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: commenting out blocks of code

2006-02-17 Thread Atanas Banov
Neil Hodgson wrote:
 Hi Steven,

  It is *easy* to detect when a line is already commented. It starts with a
  #. The ~ is superfluous.

 It is not usual to change a line from being code to being a comment
 as most lines of code make no sense as English text. If you do sometimes
 want to do this, the # key can be pressed at the beginning of a line.
 Ctrl+Q exists to allow commenting out sections of code that you do not
 want to be active. The ~ acts to differentiate these different uses of
 one language feature and makes it easy to apply the operation over
 ranges that include comments and then invert the operation.

hi.
here is something you both seems to have not considered: imagine you
make decision if ^Q has to comment or uncomment based on the 1st line
and not on each line individually in the block. so let's say i mark and
^Q this:
--
code1
#comment1
#comment2
code2


1st line is not commented, so i want to comment-out the whole blcok,
the result is
--
#code1
##comment1
##comment2
#code2


note how ## maintains where comments were. now, for the same selection,
^Q again? 1st character is #, so the editor is asked to uncomment,
dwim:
--
code1
#comment1
#comment2
code2


so there is a way to do it without #~ noise... now if we can only think
of how to do DWIM copypaste :-)!

- nas

-- 
http://mail.python.org/mailman/listinfo/python-list