Why python doesn't use syntax like function(, , x) for default parameters?
apardon at forel.vub.ac.be
Fri Mar 10 16:33:52 CET 2006
Op 2006-03-10, Roy Smith schreef <roy at panix.com>:
> 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" <firstname.lastname@example.org> 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.
Do you have trouble remembering that range(n) is actually providing the
second parameter to the function and what it does?
> 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.
I don't consider this an argument. We already have the problem that we
need to figure out what connect(20) means. connect(,,20) will at least
make it clear that some parameters are missing. My syntax doesn't
make it easier to introduce inclarities than python can.
Sure connect(port=20) provides extra clarity, but nobody seems to have
a problem with range(n) where n suddenly is the second parameter and
we use the default for the first. If we want to allow things like that
I would prefer range(,n) that at least makes it clear what is going on.
More information about the Python-list