Why not enforce four space indentations in version 3.x?
Tim Chase
python.list at tim.thechases.com
Thu Jul 16 14:40:09 EDT 2009
>> However, they are a single logical level of indentation -- I come
>> down fairly solidly on the "tabs" side of the "tabs vs. spaces"
>> argument.
>
> My bet is that the problem is this: some people like to format their
> code in ways that don't work well when you're using tabs. For example,
> they might want to call a function like this (note spaces):
>
> some_func(foo=1,
> bar=2,
> baz=3)
>
> instead of:
>
> some_func(
> foo=1,
> bar=2,
> baz=3)
For continued indenting statements such as this, I tend to use
the coding convention used at my first job out of college
(Computer Sciences Corp...for better or worse) which just indents
two levels:
def some_func(foo=1,
<tab><tab>bar=2,
<tab><tab>baz=3):
<tab>do_something(foo)
<tab>do_other_stuff(bar)
> examples for things besides function calls. Don't you ever find cases
> where you'd like to add in an extra space or two to make things line
> up nicely?
I have occasionally (okay, "very rarely") use the "mixed
tab+space" method of indentation for continued lines if I want
them lined up nicely:
<tab><tab>if (foo == bar and
<tab><tab> baz > frob and
<tab><tab> fred != barney):
<tab><tab><tab>do_something()
<tab><tab><tab>do_more()
This scheme insures that the visual alignment for the
continued-line matches up, even if the tab-stop is changed. The
positioning of the indented block (the do_* bit) floats
inconveniently with relation to the continued text, with pessimal
cases being indistinguishable from the continued lines (which is
why I generally opt not to use this unless it has great benefits
in code clarity). By regularly indenting continued lines for
containing blocks (if, while, etc) by two tabs, the continuation
stands out from the contained code regardless of my tab stops.
>> I can set my editor (vim in this case) to show tabs as
>> as many spaces as I want. I usually have this set to 4, but
>> sometimes 1 or 2.
>
> Just curious: why would you want to do that? In my experience, once my
> eyes got used to 4-space indents, everything else looks either too
> little or too much. :)
It totally depends on the project -- I like the condensed nature
of 2sp/tab for code sharing on mailing lists (and tend to copy
out of vim with tabs expanded to 2 spaces for pasting into
emails) and for my own visual preference. If it's code that I'd
expect anybody else to view, I tend to use 4sp/tab to keep my
lines below 80 chars per line with the tabs taken into consideration.
I guess I change up my indent enough that sometimes 2 seems just
right or too small, and sometimes 4 seems just right or too large.
-tkc
More information about the Python-list
mailing list