Compare source code

Steven D'Aprano steve at
Fri Nov 5 11:41:40 CET 2010

On Thu, 04 Nov 2010 20:17:35 +0000, Seebs wrote:

>>   * I /do/ have a significant problem with cutting and pasting code in
>>     Python.  In most languages, I can haul a chunk of code about, hit
>>     C-M-q, and Emacs magically indents the result properly.  This is,
>>     unfortunately, impossible with Python.  It has caused me real bugs,
>>     and I have to be extra careful to fix the indentation up.
> That was the thing which bit me the worst.  I had a fairly large block
> of code in a first-pass ugly program.  I wanted to start refactoring it,
> so I moved a big hunk of code into a method (with plans to further
> refactor).  It took about fifteen minutes to redo the logic.

Well there's your problem -- you are relying on tools that operate by 

Rather than re-create the logic, why not just hit Undo and then re-paste 
the code *without* the magic auto-reformat? Half a second, to undo and re-
paste, followed by 10 or 20 seconds to select the appropriate lines and 
*explicitly* re-indent the lines to the correct level.

For somebody who keeps tossing around the mantra that "explicit is better 
than implicit", you're amazingly reliant on a tool that performs massive, 
apparently irreversible formatting operations implicitly. And then rather 
than accept that your magic DWIM tool is unsuitable for the task you are 
putting it to, you then blame the data for not having error-correction 
codes that would allow *another* magic tool to fix the breakage caused by 
the first magic tool!


More information about the Python-list mailing list