5 ms·
Python Style Guide from Google
- orian 10y agoGoogle's C++ style guide is much more interesting: https://google.github.io/styleguide/cppguide.html https://google.github.io/styleguide/cppguide.html
- catnaroek 10y agoIn that it destroys a greater proportion of the language's expressive power? :-p
- jsolson 10y agoIt has improved considerably since the adoption of (much of) C++11. Still no exceptions, though.
- adrianratnapala 10y agoThe 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.
- jsolson 10y agoI mostly agree. We do have that in the form of static analysis, Status and StatusOr return types, and MUST_USE_RESULT (which is also visible in external codebases like V8). There's still a fair amount of boilerplate, but on the other hand control flow transfers are explicit, so it's a trade-off.
- catnaroek 10y ago> 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
- yeukhon 10y agoGoogle internally does not always follow this guide. Different project can come up with its own style.
- usmannk 10y agoThey /can/ but I've found that almost every team I've interacted with sticks with the style recommended by g4 lint.
- packetslave 10y agoNote 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 10y ago4 spaces? seriously? Why would anyone type out 4 spaces instead of one tab?
- isbadawi 10y agoYou configure your editor to expand a tab into four spaces.
- ulam2 10y agoPersonally, 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 10y agoI thought everybody does that..who the hell would type space 4 times?
- catnaroek 10y agoA good reason for sticking to monospace characters is that they're always displayed the same, regardless of your personal editor and editor configuration choices. Also, you don't need to type 4 (or however many) spaces directly. Most programming editors can be configured to insert spaces when you press tab, or to replace existing tabs in a file to spaces.
- jdboyd 10y agoVirtually everyone does type one tab and uses a text editor that expands the tab to four spaces in the file.
- jfoster 10y agoYep. I've never really understood why editors tend to replace the tab with spaces, though. It seems to work pretty much the same when indenting, but involves more backspacing and introduces more potential for error (eg. deleting 3 spaces instead of 4) when deleting. What is the advantage that spaces have over tabs?
- deleted 10y ago[deleted]
- m_mueller 10y agoOne 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 10y agoI 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)) }
- ju-st 10y agoCode with many from... imports becomes very unreadable very fast.
- Hermel 10y agoThe 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 10y agoJust 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.
- ju-st 10y agoYou can view/edit 3 files side by side instead of only one.
- ju-st 10y agoYou can view/edit 3 files side by side instead of only one.