Indenting with tabs vs spaces

Steve Lamb grey at despair.dmiyu.org
Sat Dec 1 00:29:36 CET 2001


On Sat, 24 Nov 2001 19:54:34 -0500, Dave Cinege <dcinege at psychosis.com> wrote:
> A tab has a byte value of '9'. How it's is displayed is completely arbitary, 
> subjective, and the job of your editor. The fact the file will look
> different between editors is a good thing. The idea all source files should 
> not be able to be displayed any otherway then how the author first created 
> them is:
          _Smart_

    This is because, as Python has shown, formatting does mean something.
That is why indention is important to the language and not just there for the
programmers as in other languages.  It is a visual representation of the
meaning of code.  Furthermore there are times, even in Python, where something
is better displayed visually even though it is not required by the language.
For example:

some_dict = {'Jane':{'Age':'21', 'Dept':'0001', 'Ext':'1234'},
             'John':{'Age':'22', 'Dept':'0010', 'Ext':'5678'},
             'Jeff':{'Age':'23', 'Dept':'0100', 'Ext':'9009'},
             'Jody':{'Age':'24', 'Dept':'1000', 'Ext':'8765'},
             'Jeny':{'Age':'25', 'Dept':'0110', 'Ext':'4321'}
            }

    Yeah, yeah, we'll most likely be reading from a database for things of
this nature and it is an overly simplistic example, however, it points out a
valid point.  My intent, as the original author, is better read in the format
that I have presented.  Tabs undermine this formatting.  


    What if I use 4 and you use 8?

some_dict = {'Jane':{'Age':'21', 'Dept':'0001', 'Ext':'1234'},
                         'John':{'Age':'22', 'Dept':'0010', 'Ext':'5678'},
                         'Jeff':{'Age':'23', 'Dept':'0100', 'Ext':'9009'},
                         'Jody':{'Age':'24', 'Dept':'1000', 'Ext':'8765'},
                         'Jeny':{'Age':'25', 'Dept':'0110', 'Ext':'4321'}
                        }


    The other way around?

some_dict = {'Jane':{'Age':'21', 'Dept':'0001', 'Ext':'1234'},
         'John':{'Age':'22', 'Dept':'0010', 'Ext':'5678'},
         'Jeff':{'Age':'23', 'Dept':'0100', 'Ext':'9009'},
         'Jody':{'Age':'24', 'Dept':'1000', 'Ext':'8765'},
         'Jeny':{'Age':'25', 'Dept':'0110', 'Ext':'4321'}
        }

    Are you prepared to say that either of those is far more readable than the
first example?

    And yes, we can say "Well what if the person uses crappy formatting."
Then they used crappy formatting and nothing will help that but reformatting.
However, the tools we use should not undermine our intent and meaning when we
use formatting to increase readability.

-- 
         Steve C. Lamb         | I'm your priest, I'm your shrink, I'm your
         ICQ: 5107343          | main connection to the switchboard of souls.
    To email: Don't despair!   |  -- Lenny Nero, Strange Days
-------------------------------+---------------------------------------------



More information about the Python-list mailing list