[Python-ideas] Message passing syntax for objects

Chris Angelico rosuav at gmail.com
Tue Mar 19 07:28:45 CET 2013

On Tue, Mar 19, 2013 at 12:38 PM, Mark Janssen
<dreamingforward at gmail.com> wrote:
> On Mon, Mar 18, 2013 at 5:39 PM, Steven D'Aprano <steve at pearwood.info> wrote:
>>>> >So you've replaced one method of a collections API by your magical
>>>> > operator,
>>>> >for all collections.
>>> Yes -- for all collections.  That's a pretty big gain right?
>> No, not at all. If it's a gain at all, it's a tiny, microscopic gain. But
>> it's not a gain. We lose a lot:
>> - we can no longer distinguish between *adding* something to an unordered
>> collection, and *appending* to an ordered collection;
> Your ClassName or __doc__ is supposed to make that clear, because your
> API doesn't.  This is the problem I'm referring to when I talk about
> "hyper-personal API's" -- you have to learn the programmer's personal
> language.  Even 15 years of python append and extend are still
> ambiguous and confusing.  You've adapted to this.

There are interfaces where a generic "do something with X and Y"
concept makes sense, but I don't think program code is one of them. In
a GUI, you can drag one icon (#1) onto another icon (#2), which might
accomplish any of the following:

* Move file/folder #1 into folder #2
* Copy file/directory #1 onto remote volume #2
* Print document #1 on printer #2
* Invoke program #2, passing it the name of #1
* Destroy object #1 using the settings of shredder #2
* Send email #1 to recipient #2

These are all actions that I *have done*, and all using the exact same
invocation sequence. It makes sense in context.

With code, though, there are just way too many common operations.
Since we're working at a lower level of objects and data structures,
we're going to need to do a lot more. (Of course, drag-and-drop has a
number of other UI actions possible, such as dragging a file into the
body of a folder - that provides destination AND position, so you
could use that to put something into a particular place in an ordered
collection. Plus you can hold modifier keys while dragging, or in
other ways add information. But it's still far FAR less than code can
do.) How do you identify, to the code, which message you want to pass?
The easiest way is with a keyword... a method name. Which brings us
right back to where heaps of high level languages are: method calling.


More information about the Python-ideas mailing list