[Python-Dev] PEP 3102: Keyword-only arguments (original) (raw)
Edward Loper edloper at gradient.cis.upenn.edu
Mon May 1 19:11:54 CEST 2006
- Previous message: [Python-Dev] PEP 3102: Keyword-only arguments
- Next message: [Python-Dev] PEP 3102: Keyword-only arguments
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Fredrik Lundh wrote:
And again, why would you make me, the user-programmer, type
makeperson(name=namex, age=agex, phone=phonex, location = locationx) #instead of makeperson(namex,agex,phonex,locationx) ? because a good API designer needs to consider more than just the current release.
I believe that it's quite possible that you're right, but I think more concrete answers would be helpful. I.e., how does having parameters that are syntactically keyword-only (as opposed to being simply documented as keyword-only) help you develop an API over time?
I gave some thought to it, and can come up with a few answers. In all cases, assume a user BadUser, who decided to use positional arguments for arguments that you documented as keyword-only.
You would like to deprecate, and eventually remove, an argument to a function. For people who read your documentation, and use keyword args for the keyword-only arguments, their code will break in a clean, easy-to-understand way. But BadUser's code may break in strange hard-to-understand ways, since their positional arguments will get mapped to the wrong function arguments.
You would like to add a new parameter to a function, and would like to make that new parameter available for positional argument use. So you'd like to add it before all the keyword arguments. But this will break BadUser's code.
You have a function that takes one argument and a bunch of keyword options, and would like to change it to accept *varargs instead of just one argument. But this will break BadUser's code.
I think that this kind of concrete use-case provides a better justification for the feature than just saying "it will help API design." As someone who has had a fair amount of experience designing & maintaining APIs over time, perhaps you'd care to contribute some more use cases where you think having syntactically keyword-only arguments would help?
-Edward
- Previous message: [Python-Dev] PEP 3102: Keyword-only arguments
- Next message: [Python-Dev] PEP 3102: Keyword-only arguments
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]