
Python Style Guide from Google - mmphosis
https://google.github.io/styleguide/pyguide.html
======
m_mueller
One thing I find odd is to prohibit classes / functions from being imported,
instead forcing to always write their module names for the fear of namespace
collisions. Is this common for Python in organisations? Did I get something
wrong? Seems to a little bit too much on the Java side of this tradeoff.

~~~
strajk
I prefer importing whole modules too. One of the benefit is much easier code
reviews:

Imagine this diff in the middle of a file (in Javascript)

    
    
      if (includes(users, userId)) {
        open(load(userId))
      }
    
    

vs

    
    
      if (_.includes(users, userId)) {
        Modal.open(UserApi.load(userId))
      }

------
orian
Google's C++ style guide is much more interesting:
[https://google.github.io/styleguide/cppguide.html](https://google.github.io/styleguide/cppguide.html)

~~~
catnaroek
In that it destroys a greater proportion of the language's expressive power?
:-p

~~~
jsolson
It has improved considerably since the adoption of (much of) C++11.

Still no exceptions, though.

~~~
adrianratnapala
The advantage of exceptions is not so much their "expressive power", but the
fact that they provide an approximation to error handling even when nobody
remembers to express it.

If my team had some process (via code review, static analysis, or anything
else) that could ensure error returns were actually checked and handled, then
the case for exceptions would be much diminished.

~~~
catnaroek
> some process

Or something like Rust's `Result<T,E>` type? You can't possibly forget to
`match` it, and if you `unwrap` it, it will be plain obvious, both to humans
and to linters.

[http://doc.rust-lang.org/std/result/index.html](http://doc.rust-
lang.org/std/result/index.html)

------
Hermel
The only rule that would bother me is the max line width of 80 characters. Why
still stick to this rule with today's screens? I usually set this to 200.

~~~
adrianratnapala
Just because you have a screen that can display an enourmously long line of
text, it doesn't mean that text is going to be readable. Or that you want to
use the whole width of your screen for displaying unreadable text.

Lines longer than 100 chars are very rare in readable code. And it is easy to
break lines down to 80 or even 72. If you do that, then it becomes easy to
place two windows of good sized text side-by-side.

------
yeukhon
Google internally does not always follow this guide. Different project can
come up with its own style.

~~~
packetslave
Note that this is the public style guide (intended for contributions to Google
open-source projects). The internal style guide has some differences, mainly
to more-closely match the styles of internal C++ and Java (things like naming
and indenting).

In my experience, any Python code in the core codebase follows the (internal)
style guide. Big mostly-standalone projects like YouTube have their own style.

------
mozumder
4 spaces? seriously? Why would anyone type out 4 spaces instead of one tab?

~~~
ulam2
Personally, i use tabs of size four with expandtabs setting. That way i don't
have to press four spaces and my files look the same across all editors and
platforms.

~~~
Goranek
I thought everybody does that..who the hell would type space 4 times?

