Why python doesn't use syntax like function(, , x) for default parameters?
roy at panix.com
Fri Mar 10 15:19:40 CET 2006
In article <slrne130qi.dji.apardon at rcpc42.vub.ac.be>,
Antoon Pardon <apardon at forel.vub.ac.be> wrote:
> Op 2006-03-10, Roy Smith schreef <roy at panix.com>:
> > "Dmitry Anikin" <email@example.com> wrote:
> >> There are often situations when a function has independent
> >> parameters, all having reasonable defaults, and I want to
> >> provide just several of them. In fact, I can do it using
> >> keyword parameters, but it's rather long and you have to
> >> remember/lookup names of parameters.
> > Specifying the names of the keyword parameters costs you a little typing
> > once, but saves everybody (including yourself) a lot of grief later when
> > you're trying to figure out what the heck your code does 6 months later.
> Could you explain what is so hard in figuring out:
Because while I probably remember what func does (especially if it's well
named), it's less likely that I remember all the arguments it takes, and
even less that I remember what order they come in.
Let's say I've got a function which makes a network connection. It takes
optional arguments for a port number to connect to, a timeout (in seconds)
and a buffer size (in kbytes) to use. If we used your syntax, what does
"connect (,,20)" mean? You have to go look up the definition of the
function to find out, don't you? But, if I wrote "connect (port=20)", it's
obvious to anybody reading the code what the 20 is.
More information about the Python-list