[Python-ideas] Anonymous blocks (again):

Stephen J. Turnbull stephen at xemacs.org
Tue May 14 04:54:49 CEST 2013


Haoyi Li writes:

 > Method chaining *prevents* [intermingling unrelated code] from
 > happening in the first place, which is really nice. Even if I try
 > to avoid this, I haven't seen any code base where this hasn't
 > happened in various places, causing endless headaches.

There's nothing intrinsicly wrong with your preference, but as far as
I can see it's un-Pythonic.  Specifically, as you mention method
chaining is equivalent to carrying along an implicit "this" argument.
But in Pythonic code, explicit is better than implicit.  For that
reason, methods with side effects generally have a useless return
value (case in point: .sort()).  In other words, making method
chaining difficult is a deliberate design decision.  You can disagree
with that decision, but you *do* have a choice of languages, so Python
doesn't *need* to accomodate your preference.

Also (and this is more or less specious, but I don't have enough brain
cells today to decide whether it's less or more), many people have
difficulty with the functional tools approach you present in lieu of
iteration statements.  Python does provide those tools, but they're
considered power tools to be used only when the expense in
maintainability by mere mortals is considered carefully, and decided
to be the lesser cost.




More information about the Python-ideas mailing list