[NCLUG] Looking at programming languages...

bill thorson bill at tstorms.com
Fri Jan 18 12:16:52 MST 2008


Folks,

We are working on a large project involving C, Perl, SQL and PHP and we 
have style guidelines for each.  When I was coming up with a style guide 
for our software project I didn't want to impose my personal style on 
the engineers.  What I did was read literally dozens of style guides 
from large open source and opened source projects.  I also interviewed 
our engineers to see what styles they were accustomed to.  Here is where 
we got to on tabs and spaces in our style guide

INDENTATION
<https://porter.privacynetworks.com:14043/trac/icss/wiki/CeCodeStyle#INDENTATION> 


    Indents are 4 spaces. No tab characters.

    EXECEPTION: All Makefiles require tabs

     There are editors where the tab character can be set to translate 
into 4 spaces on the screen. Don't do this because
     it doesn't help anybody else using any other editor. If you have 
the tab habit then have your editor convert any
     tab you enter into the 4 spaces

Our engineers use either emacs, vim or nedit and each have the ability 
to set tabs to use N spaced instead of tabs.  I'm sure if we wrote in 
python we would be using the same indentation guidelines.

Bill
VP Engineering
Privacy Networks, Inc

Walker, Philip M (Optical Storage) wrote:
> 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
>
>
>
>
> _______________________________________________
> NCLUG mailing list       NCLUG at nclug.org
>
> To unsubscribe, subscribe, or modify 
> your settings, go to: 
> http://www.nclug.org/mailman/listinfo/nclug
>   




More information about the NCLUG mailing list