[Python-ideas] Keyword only argument on function call

David Mertz mertz at gnosis.cx
Fri Sep 7 12:54:04 EDT 2018

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 <robertve92 at gmail.com>

>> 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 at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180907/9c3c19e1/attachment.html>

More information about the Python-ideas mailing list