[NCLUG] Looking at programming languages...

Walker, Philip M (Optical Storage) phil.walker at hp.com
Fri Jan 18 09:33:55 MST 2008


Duncan,

My intent was not to attack Python programmers, a group that I have great respect for.  The Python language itself is a work of art.

The problems caused by non-standard display of the tab character (ascii==9) in the various editors cause problems for most computer languages (C, Java, Perl, etc.).
One possible solution is to disallow the use tabs, and to require exclusive use of spaces.

The python interpreter/compiler necessarily interprets a tab character (ascii==9) as 8 spaces, although the same problem would exist with any other fixed interpretation.   The compiler cannot know how the code appears in the variously configured editors of the world, so it does what it can to accomodate the ambiguity by defining a tab character as being equivalent to 8 spaces.  This works fine, although a better choice for the Python language definition might have been to make tab characters (ascii==9) illegal.   This would present a different frustration to new developers, or to people whose favorite editor is not sufficiently configurable, but it would eliminate the ambiguity.

The comment was inspired by open source code updates I periodically recieve from a very talented Intel engineer.   His code contains mixed tabs and spaces.  I have requested that he avoid the use of spaces, or that he add the following comment within the first 3 lines of each source file:

# vim:ts=8

This would help me, since I use vim, but would leave other editors vulnerable to displaying jumbled code.

Phil


-----Original Message-----
From: Duncan McGreggor [mailto:duncan.mcgreggor at gmail.com]
Sent: Thursday, January 17, 2008 12:34 PM
To: Northern Colorado Linux Users Group
Subject: Re: [NCLUG] Looking at programming languages...

Walker, Philip M (Optical Storage) wrote:

> Python is good stuff, but one limitation prevents me from becoming enthusiastic:
>
>  the indentation relies on the assumption that tabs (if present) are unambiguously equivalent to 8 spaces.
>
> Of course, that assumption is not valid unless your editor is
> configured that way

I don't know of any python programmer that uses 8 spaces for indent. I use 4 (with vim). The twisted python coding standard dictates 4. What's more, the official python coding standard
(http://www.python.org/dev/peps/pep-0008/) suggests 4, saying that 8 should only be used if necessary (e.g., legacy code).

Google actually uses 2 spaces for all their python code. (I only do that when entering code in the interactive prompt.)

But I am curious: where do you come by this wrong information? In particular, that python assumes tabs are 8 spaces? I'm curious to know what demographic believes this to be true when the very thought is antithetical to every standard I know of and offends the sensibilities of all the python programmers I know...

> My editor (vim) is configured by default for tabs == 4 spaces, and out of respect for other developers that have to read my code, I always output files with no tabs, but many (most?) Python developers distribute files with mixed tabs and spaces.

Phil, are the python programmers you know newbs? I don't know of *any* python programmer that mixes tabs and spaces. It's one of the greatest sins you can commit in python source code, and in fact, will throw an error if used in the same block of code:

IndentationError: unindent does not match any outer indentation level

Again, I reference the python coding standard which states, in a one-sentence paragraph (for visibility and emphasis):

"Never mix tabs and spaces."

d







More information about the NCLUG mailing list