开发者

Python: Google App Engine source uses tab depth 2

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 differen开发者_如何学JAVAtly based on the tab depth. But perhaps there's a good reason for their style.


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.


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

  • http://code.google.com/p/soc/wiki/PythonStyleGuide#Indentation
  • http://groups.google.com/group/django-developers/msg/f6a86d135fb2968f


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.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜