[Python-ideas] Message passing syntax for objects

Andrew Barnert abarnert at yahoo.com
Fri Mar 22 10:08:19 CET 2013

From: Haoyi Li <haoyi.sg at gmail.com>

Sent: Thursday, March 21, 2013 11:08 AM

>I disagree completely. Coming from Java, where every list-within-list has its own special class to represent it, my experience is that is a terrible idea:

This is a side issue, but… that's not the problem with Java lists. After all, Haskell also has a separate type for every list-within-list, yet you can still use comprehensions, map/filter/reduce, etc., and they even work over abstractions rather than just lists (I promise, I won't use the m-word here). Even C++ has std::transform and friends. The terrible idea is having a rigid and non-extensible type system. Haskell (and, to a much lesser extent, C++) avoids that through explicit parameterization; Python (and, to a lesser extent, Smalltalk/ObjC/etc.) avoids it through implicit duck typing; Java forces the programmer to deal with it by writing horrible manual boilerplate.

>In the end, message sends and method calls are basically isomorphic, so much so that in Scala you can transparently convert method calls to message sends under the hood if you prefer that syntax! Unless there's some significant advantage of doing it, it seems to me that the improvement would basically be forcing people to run a regex on their code to convert obj.method(a, b) to obj << (msg, a, b), and then life goes on exactly as it did before.

Here is the main point. Everyone is reading their own ideas into the proposal, because nobody can believe it's as ridiculous as it sounds. The whole key to the proposal is that you _don't_ have messages with parameters like (msg, a, b); a message is just an object. You can do obj1 >> obj2, and that's all you ever need. obj2 knows what to do with obj1, so you don't need to tell it.

Since it's patently obvious that you _do_ need objects with more than one behavior, people assume he _must_ be talking about messages and objects in the sense of Smalltalk/Erlang/Scala/Go/etc.: a message as something that describes an action to take, with arguments. The fact that he's specifically referenced Alan Kay and Smalltalk and papers about this kind of message-sending makes that assumption even harder to avoid. But the assumption is wrong. You can't convert obj.method(a, b) to his syntax, because if you need to, obj isn't a good example of an object.

He's specifically said, multiple times, that if you think there are multiple things obj2 might want to do with obj1, that means you're not imagining the right kinds of objects. Lists, numbers, files, filesystems, servers, documents, hyperlinked webs of documents, GUI windows, database tables, events, animals, cars, ecosystems, user accounts—all of these things are bad examples of objects. And he hasn't given any good examples, no matter how many times he's been asked; the only examples he's given are lists, numbers, and filesystems, all of which he claims are terrible. While his objects are "universal", there are no such things that exist.

Except, of course, for single-argument, void-return functions. They work exactly like what he's describing as "objects". That observation has already been made three times, and he hasn't even responded. He just waits for someone else to come along, read something into his proposal that isn't there, and talk to them until they figure out he's a quack.

More information about the Python-ideas mailing list