Uniform Function Call Syntax (UFCS)

Marko Rauhamaa marko at pacujo.net
Sun Jun 8 11:56:47 EDT 2014


Paul Sokolovsky <pmiscml at gmail.com>:

> Python already has that - like, len(x) calls x.__len__() if it's
> defined

In fact, what's the point of having the duality?

   len(x) <==> x.__len__()

   x < y <==> x.__lt__(y)

   str(x) <==> x.__str__()

etc.

I suppose the principal reason is that people don't like UFCS. Plus some
legacy from Python1 days.

Lisp & co. rigorously follow its UFCS. I think it works great, but that
is what people most ridicule Lisp for.

What do you think? Would you rather write/read:

   if size + len(data) >= limit:

or UFCS-ly:

   if size.__add__(data.__len__()).__le__(limit):


Marko



More information about the Python-list mailing list