Indenting with tabs vs spaces

Tim Roberts timr at probo.com
Sat Nov 24 00:56:46 EST 2001


"Peoter Veili" <peoter_veliki at hotmail.com> wrote:
>
>> >Tabs are wrong, because different editors will treat them differently.
>> >
>> >Spaces are right, because a space is a space is a space, everywhere you
>> >go.
>
>Indenting with tabs can be done such that it will look the same on every
>editor that uses fixed-width fonts, meaning everything will line up
>correctly, it least in the sense that really matters.

That's just not true.  The crux of the problem is that "tab" does not have
a universal meaning.  As long as there is a physical tab character at the
beginning of a line, the file will look different in my vim, where tabstop
is 8, and in my Visual C++, where the default hard tab is 4.  It might look
similar, but it will not look the same.

>Here's an example of what I mean:
>
>    function helloThere("hello",
>                                       "there"){
>    }
>
>The proper way to do this is the second line needs to be typed with one tab
>followed by enough spaces to line up the "hello" and "there".

You're still assuming that the first tab you typed means "4 spaces".  Plus,
I should not have to type a jillion spaces to get that to line up.

Now, I certainly should be able to TYPE that line with the tab key, but
when it's written to file it should have spaces.  That's the only way to
guarantee that it will look the same in your editor as it looks in mine.

>Besides this I know of no problems with using tabs.  I find them cleaner and
>more efficient.  I'd rather tab 10 times than hit the space bar 40 times. I
>never have to go through a whole file and manually line things up because at
>one place in the file I accidentally didn't indent with the right amount of
>spaces and half the file needs fixing.

Right.  You should be able to hit the "tab" key 10 times (or 5 times) to
get 40 spaces, but the file you save to disk should have spaces.
--
- Tim Roberts, timr at probo.com
  Providenza & Boekelheide, Inc.



More information about the Python-list mailing list