[Tutor] Correct style of line break when chaining methods

Roel Schroeven roel at roelschroeven.net
Sun Jul 11 15:55:40 EDT 2021


Manprit Singh schreef op 10/07/2021 om 18:03:

> And Secondarily when doing work with Numpy arrays and Pandas we are mostly
> working with chained methods, and at that time, what i feel is a line break
> can increase readability also .

I think so too. As a general rule, or rather guideline, I think a line 
should as much as reasonably possible express one thought. The exact 
meaning of "one thought" is quite vague, of course; it's more the idea 
that counts than a hard rule.

In this case, I think each of the chained operations constitutes a 
separate thought and therefore deservers to be on its own line.

It can work in the other direction too: sometimes a line gets quite long 
just because there are e.g. some long identifiers in it, and it can be a 
good idea to keep it on one line even if it's a bit over 79 characters.
90-ish is the approximate cut-off I use mostly. I know, that strictly 
doesn't comply with PEP 8. I've always been a fan of "A Foolish 
Consistency is the Hobgoblin of Little Minds" in PEP 8, and "Readability 
counts" from PEP 20 (The Zen of Python). When increasing line length 
within reason aids readability/clarity, by all means go for it, I'd say.

-- 
"Honest criticism is hard to take, particularly from a relative, a
friend, an acquaintance, or a stranger."
         -- Franklin P. Jones

Roel Schroeven



More information about the Tutor mailing list