[Python-ideas] Make partial a built-in

Ryan Gonzalez rymg19 at gmail.com
Tue Sep 20 12:42:04 EDT 2016


On Sep 20, 2016 10:52 AM, "Guido van Rossum" <gvanrossum at gmail.com> wrote:
>
> On Tue, Sep 20, 2016 at 8:29 AM, אלעזר <elazarg at gmail.com> wrote:
>> *snip*
>> The alternative to partial is writing a closure in the form of a
function, that needs to be carefully inspected to verify that it is indeed
just a partial application and not something more complex. It has more
opportunity for introducing an error. And it's longer and adds distance
between related parts of the code.
>
>
> We seem to have fundamentally different ideas of what sort of code is
most readable. The alternative to partial is usually a lambda, and the
signature of the lambda helps me understand how it is being called. I don't
see how the lambda is longer or creates more distance. There are some
exceptions, when the function has a complex signature that should mostly be
preserved (and a few other, rare exceptions). But most of the uses of
partial that I found had exactly one call site and the call site was not
calling a complex signature.
>
> A big problem I have reading code that uses partial is that *unless I
already know the function being partialed*, the partial() call itself gives
me no clue about the signature of that function. So then I have to look for
the call site of the partial (what do you call that?) and then in my head I
have to combine that with the partial parameters and figure out what is
really happening. A lambda would have given me a simple stepping stone. In
effect it's a little bit of "typing" right there, showing me the signature
that's being called, which is useful for reading the code quickly.

Most often, when I see lambdas used for this, it looks like:

lambda *args, **kw: myfunc(partial_arg, *args, **kw)

which isn't more readable than just:

partial(myfunc, partial_func)

Doing something like:

lambda x, y: myfunc(partial_arg, x, y)

is more error-prone to changes in myfunc's signature. Also, I don't quite
understand the readability issue here; all partial is doing is
just...err...partializing the function (I should totally patent that
phrase). I find it easy to mentally expand it:

partial(f, ...) == lambda *args, **kw: f(..., *args, **kw)

> Also, I once timed it and could not show that partial was faster. This
surprised me but it wa what I measured (in one particular case).
>
>>
>> Elazar
>>
>>
>> בתאריך יום ג׳, 20 בספט' 2016, 18:20, מאת Guido van Rossum ‏<
gvanrossum at gmail.com>:
>>>
>>> I am radically opposed to this proposal. Every time I see a partial
application I wonder endlessly about what's going on.
>>>
>>> --Guido (mobile)
>>>
>>> _______________________________________________
>>> Python-ideas mailing list
>>> Python-ideas at python.org
>>> https://mail.python.org/mailman/listinfo/python-ideas
>>> Code of Conduct: http://python.org/psf/codeofconduct/
>
>
>
>
> --
> --Guido van Rossum (python.org/~guido)
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/

--
Ryan
[ERROR]: Your autotools build scripts are 200 lines longer than your
program. Something’s wrong.
http://kirbyfan64.github.io/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160920/b03893d8/attachment.html>


More information about the Python-ideas mailing list