views:

79

answers:

3

Looking through the Google App Engine source, I noticed that the tab depth is 2 spaces instead of the conventional 4. Is there some wisdom behind this, or is it just someone's preference?

(Maybe it's trivial, or maybe Google knows something that isn't immediately obvious.)

UPDATE I wasn't suggesting that it ran differently based on the tab depth. But perhaps there's a good reason for their style.

+2  A: 

Obviously how many spaces you use doesn't matter at all in how it runs. It's their convention:

Ken
Code readability *determines* (in part) maintainability, which *determines* "how it runs". -1 for the offhand dismissal of good code style.
Glenn Maynard
I've reread my answer a couple times, and I don't see anywhere that I "dismiss good code style", much less offhandedly. Readability determines maintainability, absolutely, but not how it *runs*.
Ken
+4  A: 

The Google Python Style Guide is published here, and, besides being generally vaster than PEP 8, it also differs from it in some aspects. However, the published version of the guide does mandate 4-space indents (like PEP 8 and like just about everybody else does).

Within Google, however, the actual rule is two-space indents (and you'll often catch me posting 2-space indented code because (a) it's habit by now, and (b) it's how my editors are set up;-). This was historically derived from the Google C++ style guide (Google used both C++ and Python essentially from day one, but I think C++ got its formal style guide first), which says

Spaces vs. Tabs

▽ Use only spaces, and indent 2 spaces at a time.

Lots of googlers code in both C++ and Python all the time, so I guess keeping minor aspects of the two style guides in sync, where feasible, is considered a productivity enhancement.

Alex Martelli
A: 

It's miserably bad style. 2-space indentation is simply unreadable. Don't copy it. Never use less than 4 spaces to indent in any language.

(Don't assume that something is good simply because Google source is doing it. If you've ever spent some time looking through the Android source you'd know that there's as much incompetently-written code developed at Google as there is at any other company.)

Glenn Maynard