[Python-ideas] Indentation, again: Problems with moving and combining code across editors.

Steven D'Aprano steve at pearwood.info
Sat Aug 30 11:55:07 CEST 2014


On Sat, Aug 30, 2014 at 11:49:41AM +0530, Milind Khadilkar wrote:
> Thanks.
> The problem is mostly when code from different people using different tools
> needs to be combined, or sample code from the internet (not from the
> well-behaved ones like github and stackoverflow) has to be tested and
> understood.
> Of course it is fun to discover the lost intentions of the original
> programmer, but it is not practical in a day job.

Are you suggesting that indentation is the *only* reason to test and 
understand arbitrary code you copy and paste from the Internet?

I don't that's a reasonable argument to make. Whether it is your day 
job, or just a hobby, you should have some understanding of what the 
code is supposed to do before pasting it into your own work. And there 
is so much more than just indentation that you have to be concerned 
about: the imports, the variables it uses, which functions it calls, can 
the code be trusted. Indentation is the least of these.

I accept that there are occasional situations where we might want to 
copy code from a website or email, and the indentation has been lost. 
But that ought to be rare. In my personal experience, I've needed to 
reconstruct the indentation from scratch perhaps three or four times in 
the last ten years. Even if I'm off by a factor of ten, let's call it 
three or four times a year. That's still not very important. Worrying 
that this is "not practical" in a day job seems to be worrying over 
nothing.


> QUOTE
> Because we *already have it*: the character is ' '.
> UNQUOTE
> The problem with ' ' is that a sequence of ' 's can't easily be counted,
> especially on feature rich editors.
> A sequence of '.' or some visible character can be counted.

I don't think that's a reasonable argument. I trust you're not using 
Notepad, are you? In a bare-bones editor, it's hard to count *any* long 
sequence of characters. Quick, how many dots before the X?

   ..................X

If you are a professional programmer, or even just a serious amateur, 
you should be using professional tools. With professional tools, you 
rarely need to *count the spaces*. You just need to notice changes to 
the indent level:

            one level
                another level
        different level

You don't need to care precisely how many spaces (or tabs) are there, 
you just need to ensure things line up. And any decent programming 
editor will give you the tools to increase or decrease indentation over 
a block of lines, without caring about the specific number of spaces or 
counting exactly how many spaces are needed. That includes a wide range 
of IDEs and editors of all sorts of power, on many different platforms: 
Notepad++ or geany on Windows, kate or kwrite on KDE, vim and emacs for 
pretty much any Unix or Linux system, to mention only a few.

Which brings us to another problem with your suggestion. Professional 
editors already know about indentation with tabs, and spaces, but I 
don't know any editor which gives you the ability to indent with 
arbitrary characters. (Although I daresay somebody would soon write a 
macro for Emacs to do that.) Which means you are swapping from a system 
where professional-quality programming tools can do the counting for 
you, to a situation where you actually do need to count the dots 
yourself. And that's a big step backwards.

I don't think this change is practical, or useful. And it's ugly.


-- 
Steven


More information about the Python-ideas mailing list