4 ms·
I seem to remember they used to indent Python code with 2 spaces. Glad to see it's 4 now.
by saghul 4y ago
I seem to remember they used to indent Python code with 2 spaces. Glad to see it's 4 now.
- simonh 4y agoI agree 4 spaces is preferable, but working in a code base with both conventions due to legacy code is hardly ideal.
- atorodius 4y agoI liked the look of 2 spaces tbh. Code had a certain „compact“ feeling to it combined with the 80 column limit.
- Jensson 4y agoWhich is why I use 3. I noticed 4 was easier to read, but was too bloated, so why not 3? Is there some specific reason why they want even numbers? 3 seems so right to me. Edit: Did someone seriously downvote me for how many spaces I indent with? Funniest downvote I've gotten so far.
- Kwpolska 4y agoFor an even better feeling, combine 2 spaces with a more sensible line length. Why does the Google Python style guide allow only 80 columns and 4 spaces, but the Java style guide allows 100 columns and 2 spaces? Python may be simpler than Java, but the difference feels too large IMO, and it’s time to get rid of old TTY vestiges and embrace the larger screens.
- vultour 4y agoNo, anything above 80 characters per line doesn’t fit two documents on the screen at the same time. Not everyone codes with a font size of 10.
- Kwpolska 4y agoThis depends on your font size and on your screen size. I can manage 230 columns with 14px Consolas on a 1080p screen, which is plenty for two 100-column documents, and almost enough for 120-column. And even if it won’t fully fit, most lines don’t reach the length limit, and for the remaining ones, in a two-file scenario, you could enable the soft word wrap feature of your editor, or just cut them off and scroll a little when absolutely necessary.
- tiagod 4y agoJava is much more verbose than python, lines get a lot longer.
- ttyprintk 4y agoFwiw, I didn’t care about any of this until I worked with a visually-impaired programmer. In fact, a better article would have been to try and predict the eye powers of a programmer based on their formatting choices.
- u801e 4y agoWhen dealing with screen splits, max line length is important. If I have my screen split vertically, I can't display more than 90 characters per line without having to horizontally scroll or deal with soft wrapping even with a large screen. If I'm resolving conflicts using a 3 way vertical split with diff3, having a shorter line length is even more important.
- GavinAnderegg 4y agoIt’s strange that some code in the style guide is still 2-space intended, though. For example, all the code from 3.19.3 until the end of the document.
- bru 4y agoIt's still 2 spaces. This is the public version of the style guide, using 4.
- omoikane 4y agoI am pretty sure it used to be 2 spaces as well. Some public repositories such as https://github.com/tensorflow/tensorflow/tree/master/tensorflow/python https://github.com/tensorflow/tensorflow/tree/master/tensorf... appear to use 2 space indent throughout. I think all these will be covered by the "be consistent" clause, and whoever made the first commit decides the style.