On Sun, Jun 28, 2020 at 02:23:38PM -0000, [email protected] wrote:
> Is possible some day add Uniform Function Call Syntax (UFCS) in Python like
> Dlang?
>
> Example: https://tour.dlang.org/tour/en/gems/uniform-function-call-syntax-ufcs
That converts calls like:
a.fun()
to
fun(a)
I don't think that will be a good match for Python. In D, the compiler
can decide at compile time:
- the instance `a` has no `fun` method;
- there is a global function `fun`;
- which takes a single parameter that matches the type of `a`;
and so convert the method call to a function call at compile time, with
no loss of efficiency or safety.
But in Python, none of that information is available until runtime:
- the compiler doesn't know what type `a` will have;
- whether or not it has a `fun` method;
- whether or not there is a global function `fun`;
- and whether it takes an argument matching `a`.
So all of that would have to happen at run time. That means that using
UFCS would make slow code. The interpreter would have to try calling
`a.fun()`, and if that failed with an AttributeError, it would then try
`fun(a)` instead.
--
Steven
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/TGGNWJPMKBYYTENDMGYYV2I5QEBTNJGP/
Code of Conduct: http://python.org/psf/codeofconduct/