Tabs versus Spaces in Source Code

achates aylwyn at
Tue May 16 19:22:55 CEST 2006

Duncan Booth wrote:

>but I prefer editors which keep things
>simple. The tab key is particularly prone to excessively complicated
>actions, for example the editor I use has the following (not simple at
>all, and in fact not even an accurate description of what it does) binding
>for the tab key:

<description of strange tab-key binding behaviour>

I'm not familiar with your editor, but if that's its default behaviour
when you hit tab then it sounds neither simple nor intuitive.

You haven't explained why you think there's a problem with having a
character which, in an unambiguous and non-implementation-specific way,
means 'one level of indentation'. In Python, of all languages, it makes
sense to have such a character because 'one level of indentation' is a
syntactical token processed by the interpreter.

But consider this: like all real men, I normally program in hex. Here's
an example of some recent code:

0x66 0x6f 0x72 0x20 0x69 0x74 0x65 0x6d 0x20 0x69 0x6e 0x20 0x6d 0x65
0x6e 0x75 0x3a 0x0d 0x0a 0x09 0x70 0x72 0x69 0x6e 0x74 0x20 0x27 0x73
0x70 0x61 0x6d 0x27 0x0d 0x0a 0x70 0x72 0x69 0x6e 0x74 0x20 0x27 0x6c
0x6f 0x76 0x65 0x6c 0x79 0x20 0x73 0x70 0x61 0x6d 0x27

If I wanted to be girly about it I could use an editor, and it would
probably look like this:

for item in menu:
	print 'spam'
print 'lovely spam'

But then if I wanted, I could write my own editor, and make it display
tabs as 'negative indents' from column 40, so that it looks like this:

                                        for item in menu:
                                print 'spam'
                                        print 'lovely spam'

Guess what: the python interpreter wouldn't know about my strange
editor habits! It would read my file and run just fine. What's more you
can view it with *your preferred indentation display methodology* and
we can both live in harmony!

With spaces for indentation, this just isn't possible, because I have
to conform to your viewing preferences, and that makes me unhappy. Why
would you want to make me unhappy?

More information about the Python-list mailing list