On Tue, Sep 20, 2016 at 8:29 AM, אלעזר <elazarg@gmail.com> wrote:
Guido, can you please elaborate?
"What's going on" is usually that the same arguments are going to be passed over and over again, and the programmer wanted to avoid this repetition. The other option is adjusting the function to a predefined interface.
I did a little searching on a large Python code base I have access to, and that's not what I found. The partial calls don't seem to produce code that's in any way clearer than the equivalent use of lambda would. My conclusion is that most people who are, um, partial to partial do so out of a habit (or perhaps a belief that it's more performant), not to make their code clearer. (FWIW I found an order of magnitude more uses of lambda than of partial in the same code base.)
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. 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@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@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
-- --Guido van Rossum (python.org/~guido)