3 ms·
What I like to do is configure black for a maximum line length of 100 characters (although I prefer keeping docstrings at a maximum of 72 characters). That's no
by Dunedan 5y ago
What I like to do is configure black for a maximum line length of 100 characters (although I prefer keeping docstrings at a maximum of 72 characters). That's not as restrictive as black's default of 72 characters, but still compact enough to be readable and to fit at least two files next to each other.
If a line is longer than that it's most of the time either something which should be wrapped into multiple lines anyway (like a dictionary with multiple keys) or a sign for code smell.
One of the most common code smells I see leading to longer than necessary lines (and which might make the code harder than necessary to read) is not using early returns.
Also using a trivialized example:
to_add = []
for item in data.new_items:
if item not in data.old_items:
# code spanning multiple lines with further indentation levels
…
to_add = []
for item in data.new_items:
if item in data.old_items:
continue
# code spanning multiple lines with further indentation levels
…