[Python-ideas] Keyword only argument on function call

Chris Barker chris.barker at noaa.gov
Mon Sep 10 15:52:14 EDT 2018


On Sun, Sep 9, 2018 at 7:37 AM, Anders Hovmöller <boxed at killingar.net>
wrote:

I've spent this whole thread thinking: "who in the world is writing code
with a lot of spam=spam arguments? If you are transferring that much state
in a function call, maybe you should have a class that holds that state? Or
pass in a **kwargs dict?

Note: I write a lot of methods (mostly __init__) with a lot of keyword
parameters -- but they all tend have sensible defaults, and/or will have
many values specified by literals.

Then this:

> It would almost certainly become the strongly preferred way to do it for
> some cases like .format() and sending a context to a template renderer in
> web apps. But that’s because in those cases it is very important to match
> the names.


OK -- those are indeed good use cases, but:

for .format() -- that's why we now have f-strings -- done.

for templates -- are you really passing all that data in from a bunch of
variables?? as opposed to, say, a dict? That strikes me as getting code and
data confused (which is sometimes hard not to do...)

So still looking for a compelling use-case

-CHB

-- 

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180910/70f237f9/attachment.html>


More information about the Python-ideas mailing list