On Fri, Sep 7, 2018 at 2:22 PM Rhodri James <rho...@kynesim.co.uk> wrote: > > Top posting for once, since no one is quoting well in this thread: > > Does this in any way answer David's question? I'm serious; you've spent > a lot of words that, as best I can tell, say exactly nothing about how > keyword arguments would help that quadratic function. If I'm missing > something, please tell me.
I read Robert's response as saying, 1. The quadratic formula and its parameter list are well-known enough that you shouldn't use different names or orders. 2. Even still, there are cases where the argument expressions are long enough that you might want to bind them to local variable names. However, I don't think David's example/question is fair in the first place. Robert said that passing as keywords can be useful in cases where the order is hard to remember, and David responded with an example where the argument order is standardized (so you wouldn't forget order), then talked about "forcing" callers to use certain variable names (which I don't think is warranted). On Fri, Sep 7, 2018 at 2:22 PM Rhodri James <rho...@kynesim.co.uk> wrote: > > Top posting for once, since no one is quoting well in this thread: > > Does this in any way answer David's question? I'm serious; you've spent > a lot of words that, as best I can tell, say exactly nothing about how > keyword arguments would help that quadratic function. If I'm missing > something, please tell me. > > On 07/09/18 18:17, Robert Vanden Eynde wrote: > > If you want to force using pos args, go ahead and use Python docstring > > notation we'd write def quad(a,b,c, /) > > > > The names should not be renamed because they already have a normal ordering > > x ** n. > > > > This notation is standard, so it would be a shame to use something people > > don't use. > > > > However, I recently used a quad function in one of my uni course where the > > different factors are computed with a long expression, so keyword > > arguments, so I'd call: > > > > Vout = quad( > > a=... Some long expression > > spanning a lot of lines ..., > > b=... Same thing ..., > > c=... Same thing...) > > > > Without the a= reminder, one could count the indentation. > > > > And if you'd think it's a good idea to refactor it like that ... > > > > a = ... Some long expression > > spanning a lot of lines ... > > b = ... Same thing ... > > c = ... Same thing... > > > > Vout = quad(a,b,c) > > > > Then you're in the case of quad(*, a, b, c) (even if here, one would never > > def quad(c,b,a)). > > > > Wheter or not this refactor is more clear is a matter of "do you like > > functional programming". > > > > However, kwargs arz more useful in context where some parameters are > > optional or less frequentely used. But it makes sense (see Pep about > > mandatory kwargs). > > > > Kwargs is a wonderful invention in Python (or, lisp). > > > > Le ven. 7 sept. 2018 à 18:54, David Mertz <me...@gnosis.cx> a écrit : > > > >> Here's a function found online (I'm too lazy to write my own, but it would > >> be mostly the same). Tell me how keyword arguments could help this... Or > >> WHAT names you'd give. > >> > >> > >> 1. def quad(a,b,c): > >> 2. """solves quadratic equations of the form > >> 3. aX^2+bX+c, inputs a,b,c, > >> 4. works for all roots(real or complex)""" > >> 5. root=b**2-4*a*c > >> 6. if root <0: > >> 7. root=abs(complex(root)) > >> 8. j=complex(0,1) > >> 9. x1=(-b+j+sqrt(root))/2*a > >> 10. x2=(-b-j+sqrt(root))/2*a > >> 11. return x1,x2 > >> 12. else: > >> 13. x1=(-b+sqrt(root))/2*a > >> 14. x2=(-b-sqrt(root))/2*a > >> 15. return x1,x2 > >> > >> > >> After that, explain why forcing all callers to name their local variables > >> a, b, c would be a good thing. > >> > >> On Fri, Sep 7, 2018, 12:18 PM Robert Vanden Eynde <robertv...@gmail.com> > >> wrote: > >> > >>> > >>>> I disagree. Keyword arguments are a fine and good thing, but they are > >>>> best used for optional arguments IMHO. Verbosity for the sake of > >>>> verbosity is not a good thing. > >>> > >>> > >>> I disagree, when you have more than one parameter it's sometimes > >>> complicated to remember the order. Therefore, when you name your args, you > >>> have way less probability of passing the wrong variable, even with only > >>> one > >>> arg. > >>> > >>> Verbosity adds redundancy, so that both caller and callee are sure they > >>> mean the same thing. > >>> > >>> That's why Java has types everywhere, such that the "declaration part" > >>> and the "use" part agree on the same idea (same type). > >>> _______________________________________________ > >>> Python-ideas mailing list > >>> Python-ideas@python.org > >>> https://mail.python.org/mailman/listinfo/python-ideas > >>> Code of Conduct: http://python.org/psf/codeofconduct/ > >>> > >> > > > > > -- > Rhodri James *-* Kynesim Ltd > _______________________________________________ > Python-ideas mailing list > Python-ideas@python.org > https://mail.python.org/mailman/listinfo/python-ideas > Code of Conduct: http://python.org/psf/codeofconduct/ _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/