4 ms·
Find an example in your code base where you had to go over 80 characters. find . -name '*.py' | xargs grep -n '^.\{80\}' and post it here.
by zepolen 10y ago
Find an example in your code base where you had to go over 80 characters.
find . -name '*.py' | xargs grep -n '^.\{80\}'
and post it here.
- raverbashing 10y agoYou "don't" need to go over 80 chars. 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)
- stinos 10y agoBy that reasoning you could almost say 'find an example where you had to go over [insert arbitrary number between 50 and 100 or so]'. If the number if low enough or my screen is wide enough I could fit 4 text editor panes next to each other :] Any code could probably be broken up to match that as well. 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.
- fnord123 10y agoNot python, but in Java, identifiers can get quite long. e.g.: "localizableRUNTIME_MODELER_PORTNAME_SERVICENAME_NAMESPACE_MISMATCH" is the longest at 66 characters. 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.
- raverbashing 10y agoBut the 80 characters limit includes indentation
- pvg 10y agoLeading indentation is very much a part of the results especially in a language like python where the indentation is syntactically significant. You can't just decide to toss it to make a line shorter.
- dozzie 10y ago> As for python, some fancy list comprehensions get rather long rather quickly. 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(...) ]
- dood 10y agoPreventing people making unreadable list comprehensions is exactly the sort of thing the 80 character limit is for ;)
- pvg 10y agoTry this on the python source itself and you'll find a lot of perfectly reasonable examples. One problem is that in a method, your first meaningful indent is actually three (12 spaces in) - two are eaten up in declaration ceremony. In a language with delimiters instead of significant whitespace you could just fiddle with the convention - for instance, you could decide that you're just not going to give up a full indent for toplevel class members. This isn't an option in Python.
- chriswarbo 10y ago> One problem is that in a method, your first meaningful indent is actually three (12 spaces in) - two are eaten up in declaration ceremony. 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!)
- pvg 10y agoFor all the 'multi-paradigm' talk, it's still mostly an OO language and almost everything non-trivial written in python is structured in classes and methods. So that's 12 spaces with your first real indent. It's not the end of the world (nor do I think it's there to discourage one from using classes and methods) but it makes it easy enough to hit 80 chars to the point where a strict 80 column limit is a little too restrictive.
- ezl 10y agoi just love that i had never thought of trying to find lines of code of a certain length this way and you probably just wrote it without a second thought. hn is such a cool place. :)