Google and Python code
http://panela.blog-city.com/python_at_google_greg_stein__sdforum.htm21st of February 2006
After reading Matt Harrison's notes about Python at Google I noticed something which I couldn't add up.
"Python programmers at Google must follow a strict style guideline (based on PEP8 with 2 spaced indenting). When engineers are first granted commit access to their SCM system, they must pass a style test."
"based on PEP8" but rejecting such an important part as indentation really is.
From PEP 8 Style Guide for Python Code
"Use 4 spaces per indentation level."
All Python code from Google Code uses 2 spaces (not tabs) and that's not what Guido uses or recommends.
I know this is an anal issue to nag about but I was modifying some code today that uses 2 spaces and I just think it's more difficult to scan. Look at this Google code for example (from GTags):
retval = ''
i = 0
while sexp[i] != '"':
i = i + 1
i = i + 1 # skip opening "
while sexp[i] != '"':
if sexp[i] == '\\':
i = i + 1 # skip over \
if preserve_backslashes:
retval += '\\'
retval += sexp[i]
else:
retval += sexp[i]
i = i + 1
return (i, retval)
Compared to the same code but formatted according to PEP 8:
retval = ''
i = 0
while sexp[i] != '"':
i = i + 1
i = i + 1 # skip opening "
while sexp[i] != '"':
if sexp[i] == '\\':
i = i + 1 # skip over \
if preserve_backslashes:
retval += '\\'
retval += sexp[i]
else:
retval += sexp[i]
i = i + 1
return (i, retval)
Notice how the Google code also formats their parameters:
And again, this is what PEP 8 says on the subject:
def complex(real, imag=0.0):
return magic(r=real, i=imag)
No:
def complex(real, imag = 0.0):
return magic(r = real, i = imag)
Why Google? Why can't you adhere to the more readable PEP 8 now that you've started sharing your code on Google Code
Tweet