News for hackers. Stuff that matters.
Re:Google Python Style Guide by tvon on Saturday May 01, 2010 @04:37PM (#1311196)
A "how this differs from PEP8" summary would be useful to me, assuming it differs.
Re:Google Python Style Guide by d0mine on Saturday May 01, 2010 @07:35PM (#1311459)
The crucial difference:

Google (original formatting):

  BE CONSISTENT. 
PEP8:

  A Foolish Consistency is the Hobgoblin of Little Minds
Re:Google Python Style Guide by sigzero on Saturday May 01, 2010 @07:41PM (#1311478)
No...those are different. One is just telling you to "be" consistent and the other is telling you not to be "foolish" about it. Much different in my mind.
Re:Google Python Style Guide by vcrash on Saturday May 01, 2010 @09:49PM (#1311725)
Seeing as the response is to a comment asking for differences, wouldn't it make sense to assume that it shows differences? In fact, the response notes that they are an example of a "crucial difference".
Re:Google Python Style Guide by tvon on Sunday May 02, 2010 @01:15AM (#1312005)
I think sigzero means "different" as in "not contradictory or in conflict"
Re:Google Python Style Guide by d0mine on Tuesday May 11, 2010 @07:57AM (#1337515)
Google uses CAPS LOCK that I understand as a command "be consistent no matter what".

The quote from PEP8 translates in my mind to "be consistent if it's worth it".

These policies are not orthogonal. You can't satisfy both in all cases.

Re:Google Python Style Guide by etal on Saturday May 01, 2010 @10:35PM (#1311799)
I had thought the main difference was indenting with 2 spaces instead of 4, but this style guide says 4 spaces, too. I guess Google deliberately brought themselves in sync with the Python mainstream.

This style guide looks like a superset of PEP 8 -- where PEP 8 describes what Python code should look like, this guide goes through every Python feature and lays out exactly where a sizable group of top-notch Python hackers were willing to draw the line on maintainability vs. whipupitude for large, long-running projects.

Re:Google Python Style Guide by durin42 on Sunday May 02, 2010 @01:25AM (#1312018)
This is decidedly not the same as the internal guide. 2-space indents are the norm, and functions_like_this are supposed to be spelled FunctionsLikeThis (yes, with the leading capital). Those are the two big differences from PEP8 that I can think of.
Re:Google Python Style Guide by ableal on Saturday May 01, 2010 @05:02PM (#1311226)
> Indent your code blocks with 4 spaces.

I had this notion it formerly was 2 spaces (too little, IMH-once-bitten-O). Anyone know when it changed, if it did ?

P.S. In http://groups.google.com/group/django-developers/msg/f6a86d1... , back in Aug.2008, GvR says "Most of it [Google's unpublished internal Python style] is simply PEP-8 with 2-space indents."

(I dislike 2 spaces, once bitten by missing an indentation bug. I try to stick to 80 columns - both for print and side-by-side on screen - and think that more than 4 or 5 levels of indentation is "doing it wrong".)

Re:Google Python Style Guide by epochwolf on Saturday May 01, 2010 @05:24PM (#1311263)
I've always seen python style guides requiring 4 spaces. (With exceptions for 8!)

Ruby has standardized on 2 spaces.

I've noticed in my own experience that 2 spaces is not enough to read python quickly. 2 spaces works fine in ruby because whitespace isn't significant, you can find the end of a control structure by looking for the end keyword.

Re:Google Python Style Guide by Luyt on Saturday May 01, 2010 @09:13PM (#1311644)
It was 2 spaces indeed when I first saw these guidelines (about a month ago)
Re:Google Python Style Guide by ableal on Sunday May 02, 2010 @04:53AM (#1312224)
Thanks, I suppose you mean the internal Google style. Curiously, in that Django thread I linked above, the next post mentions this: http://code.google.com/p/soc/wiki/PythonStyleGuide

Which is a style guide for the "SoC framework, and Melange web applications", updated Jun.2009; it does specify 2 spaces, duly noted as a difference from PEP-8.

Re:Google Python Style Guide by DannoHung on Saturday May 01, 2010 @05:27PM (#1311269)
What's wrong with 2 spaces? I like 2 spaces.
Re:Google Python Style Guide by ntoshev on Sunday May 02, 2010 @01:45AM (#1312040)
I like them too, the problem is when you want to use (paste) some code that is not yours - you need to re-indent it.
Re:Google Python Style Guide by sigzero on Saturday May 01, 2010 @06:33PM (#1311353)
Then use 2 spaces. To me 2 spaces squishes code to close together. I like 4 spaces so that is what I use. You can always sift your code through a code formatter if there are differing standards on whatever project you are on.
Re:Google Python Style Guide by viraptor on Saturday May 01, 2010 @07:48PM (#1311492)
Or just use tabs, so everyone can set the display to what they like (without actually rewriting the file).

/me hides before the flames start :)

Re:Google Python Style Guide by sigzero on Saturday May 01, 2010 @06:44PM (#1311366)
Within each grouping, imports should be sorted lexicographically, ignoring case, according to each module's full package path.

  import foo
  from foo import bar
  from foo.bar import baz
  from foo.bar import Quux
  from Foob import ar
That seems kind of time consuming...
Re:Google Python Style Guide by etal on Saturday May 01, 2010 @09:45PM (#1311717)
Some text editors have a function for sorting text in-place. Vim does, and I assume Emacs does too.

Sorting makes it easier to recognize a common grouping of imports (e.g. some recurring functionality that requires three particular modules) without inspecting the words carefully.

Re:Google Python Style Guide by endgame on Sunday May 02, 2010 @09:51AM (#1312454)
Emacs: M-x sort-lines
Re:Google Python Style Guide by njharman on Saturday May 01, 2010 @09:24PM (#1311671)
> which should inherit from the built-in Exception class

I hate that. should inherit from StandardError IMNSHO. It's a quibble though and a pointless one until the standard library follows that. (which it never will...)

> Use the "implicit" false if at all possible.

Is so wrong, for the listed caveat reasons and more. It's the opposite of readability to me. Similar issues with the use default iterators. If my loop is expecting a dictionary and to iterate over it's keys I really want the "foo has no method keys" error rather than looping over a list and creating hard to discover/understand bug.

Re:Google Python Style Guide by 1amzave on Sunday May 02, 2010 @04:16AM (#1312188)
I enjoyed this bit of example code:

  x = '%s, %s!' % (imperative, expletive)
A decidedly familiar sentence structure...
Re:Google Python Style Guide by Qz on Saturday May 01, 2010 @09:28PM (#1311682)
I don't know if this is just me, but the page looks super ugly on Firefox.
Re:Google Python Style Guide by pgbovine on Saturday May 01, 2010 @10:06PM (#1311752)
agreed that it looks super ugly. but it's probably meant first and foremost to be internal documentation, so i doubt that the writers cared to make it all snazzy using translucent boxes with rounded corners and jquery rollover effects.