PEP8 and 4 spaces

Simon Ward simon+python at bleah.co.uk
Thu Jul 3 21:44:38 CEST 2014



On 3 July 2014 18:31:04 BST, Tobiah <tshepard at rcsreg.com> wrote:
>Coworker takes PEP8 as gospel and uses 4 spaces
>to indent.  I prefer tabs.  Boss want's us to
>unify.

This isn't worth arguing about. Pick a convention, it's probably going to be a compromise, get used to it. PEP8 is as good a base as any, and is (mostly) directly supported by various syntax checking tools such as flake8 and pylama (which I think both use the pep8 tool underneath), and the modes of various editors. Any good editor will make indentation painless, whichever method you settle on.

>Anyway, I gave up the 80 char line length long
>ago, having little feeling for some dolt on
>a Weiss terminal that for some reason needs to
>edit my code.

Putting the code factoring considerations aside, because others have already mentioned them and I'm sure others will, there are some other practical reasons for limiting line width:

I often use multiple editors side-by-side or in split window mode. If I'm limited to one screen I'll probably also have documentation open on that screen. Having to side scroll, or have a single editor take up most of the width of the display forcing switching between windows, seems to me to be more harmful than good for productivity.

There is plenty of research on the readability of prose, less so on code, but some of the considerations apply to code too. I'll pick out three of them.

The first probably applies less to code (because code is generally line-based and the line widths vary; it's not just a big wall of text): people tend to find it harder to track from one line to the next with longer lines of text.

The second has to do with focus: as the reader continues along a line of text their focus dwindles, it seems that starting a new line renews focus.

Thirdly, it may seem unintuitive given that we appear to have more capacity for horizontal movement of the eyes, but excessively long lines can cause more work for them potentially inducing eyestrain. We focus near the centre. Our peripheral vision either side is less discerning of details and more on movement (such as an attacker). We must move our eyes to continue reading long lines, and possibly even move our heads. This is a problem for vertical movement too, and happens if lines are too short. (I have no idea how this affects readers of vertical scripts.)

> I feel rather the same about the
>spaces and tabs, given that most people seem to
>be using editors these days that are configurable
>to show tabs a four characters.

Conversely, those same editors can probably automatically indent and unindent a configurable amount of spaces. If you don't use such an editor, and you really can't tolerate the different style, you can use another tool to reindent your code.

Simon



More information about the Python-list mailing list