[Python-ideas] Method chaining notation

Andrew Barnert abarnert at yahoo.com
Mon Feb 24 14:10:58 CET 2014


From: Stephen J. Turnbull <stephen at xemacs.org>

Sent: Sunday, February 23, 2014 3:31 PM


> spir writes:
>>  On 02/23/2014 06:06 AM, Andrew Barnert wrote:
>>  > All you're arguing here is that PyGtk is badly designed, or that
>>  > Gtk is not a good match for Python, so you have to write
>>  > wrappers. There's no reason the wrapper has to be fluent instead
>>  > of declarative.
> 
>>  That's what I was about to argue. I don't understand why the python
>>  wrapper does not let you construct widgets in one go,
> 
> *Because* it's a *wrapper*, which leverages the gobject-introspection
> FFI.  (gobject-introspection is an export-oriented FFI, rather than an
> import-oriented FFI like ctypes.)


[snip]

> I don't think you need to except subwidgets.  They could be defined
> recursively by including calls to their constructors in the
> "description" of the parent.


I think the problem here is that, to everyone who doesn't like the method chaining idea (like all three of us), it's obvious that this could be done declaratively, and it's also obvious why that would be better than writing code which breaks both Python and Gtk+ idioms, and therefore none of us have explained those obvious facts very well to the people who like the idea.

So I put together examples for both the PyGtk example that started this thread and the Java example that started the whole fluent-interface fad, along with an explanation of why method chaining is neither necessary in, nor a good fit for, Python even though it's very useful in languages like Java. See https://stupid-python-ideas.runkite.com/fluent-pythonic/ for the whole thing.

That being said, I think Nick's examples using with statements should be enough to show that there are more Pythonic solutions (that already work today) than adding chaining.


More information about the Python-ideas mailing list