by zepolen · 9y ago · 0 comments
80 characters helps a lot since you can count on all code to fit within a certain area - so you can run three side/side text buffers in your text editor, instead of two with lots of useless white space because a few lines might be too long.
Doing a simple overview of the requests library, most of the lines over 80 characters are just laziness such as:
https://github.com/kennethreitz/requests/blob/master/tests/t...
And a few of the actual potential cases for going over 80 characters can still be broken down without losing any readability:
https://github.com/kennethreitz/requests/blob/master/request...
r.headers['Proxy-Authorization'] = _basic_auth_str(self.username,
self.password)3 side/side buffers is arbitrary, (it would be 2 on a small laptop display) - and maybe that's why I like 80 characters, it lets me develop on any screen without needing more real estate because the files are long.
I mean Angular has iirc 120 characters, and if you take a look at an average source file eg:
https://github.com/angular/angular/blob/master/modules/%40an...
You'll see a ton of white space after 80 characters that is 'wasted' - this also eats up into horizontal real estate of another buffer which in the end means you actually have less information on the screen with >80 characters rather than more.
In all cases - the code in that file could easily be broken into multiple lines and not lose any readability.
It's about 1/3 of my 13" 2013 Macbook Air - the other 2/3 is usually a browser.
It's also not even about how much horizontal space there is for any reason - it just scans better if you keep it narrower.
Yes, it can. It also might end up being: a) less readable, b) uglier
Resources are limited so I'd rather devote my efforts to fixing major styling problems rather than a line that goes over 3 characters
Having a hard limit is overblown nitpickness (and even the 1st line of Pep8 warns you against those)
Not to mention how to do line continuation involves different conflicting styles
find . -name '*.py' | xargs grep -n '^.\{80\}'
and post it here.But it's stupid to break a line like this in two
stuff.do_something_funny(abc, def, ghi)
when the limit is reached at the 3rd parameter (or worse, at the parenthesis)
Don't get me wrong, I personally think 80 is a fine number and it's what I use myself. But making things like this hard rules for what basically are arbitrary reasons (e.g. depending on screen resolution) doesn't seem right in my book. I'm seriously not even considering doing something about a line if it's 81 characters.
I think that's just as reasonable as the rest of Python's whitespace usage, since it (hopefully!) causes the programmer to consider whether that ceremony (classes, methods, etc.) is neccessary or just overcomplication.
It's directly comparable to, say, nesting lambdas in lambdas in lambdas; probably not great for readability, etc. It just-so-happens that in Python's OO, that first lambda is called a class and the second is called a method (objects are a poor man's closures, and closures are a poor man's object!)
As for python, some fancy list comprehensions get rather long rather quickly. Especially if itertools are involved as you izip, etc. Or using useful variable names (i.e. not 'fcnt', 'tcnt') while destructuring as in this example from pyspark/mllib:
(failure_count, test_count) = doctest.testmod(globs=globs, optionflags=doctest.ELLIPSIS)
I adapted your grep to:
find . -name '*.py' | xargs grep -n '^ *.\{80\}'
So leading indentation doesn't mess with the results.Sure, and we all know that indentation in Python is not allowed for list comprehensions.
class Foo:
# ...
def bar():
# ...
if baz:
# ...
result = [
y.strip()[1:14].replace("this", "that")
for x in nabla.generate(q, w, y, z)
for y in x.something_other()
if y.has_property(...)
]hn is such a cool place. :)
Does anyone else feel this way? Or I like it because I had to do it and therefore had to like it in the process.
Then I was assigned a project where this was enforced in the test suite and had to religiously follow pep8. It took a while to get used to but after a while the benefits (like fitting into everyone's editor configuration, cleaner list comprehensions etc) became apparent.
Now I'm the one to put flake8 as a part of the test suite in any new python project :)
I've found that in the absence of a hard limit, you all too quickly end up with a codebase riddled with 250+ line monsters forcing you to scroll right and left all over the place just to get the faintest smidgen of an idea of what's going on. It's a maintenance nightmare.
Meanwhile, GitHub won't show lines longer than 132 characters (on Windows) or 123 characters (on the Mac) without scrolling, no matter how wide your screen.
I personally find 100 seems to strike the right balance.
I typically go with 'about 1/3 of my screen width' so I can develop in multiple windows without horizontally scrolling. That's a lot more than 80 chars on a 4k screen.
Add the fact that there still are people who print the code on paper out there.
C tends to be terse, so easy to imagine things under 80
python (due to lack of decent types/more verbose community) has more of a need for those 80 chars.
I think there's likely a per-project line limit that "makes sense".