Why python doesn't use syntax like function(, , x) for default parameters?
Steve Holden
steve at holdenweb.com
Fri Mar 10 08:17:24 EST 2006
Dmitry Anikin wrote:
> I mean, it's very convenient when default parameters
> can be in any position, like
> def a_func(x = 2, y = 1, z):
> ...
> (that defaults must go last is really a C++ quirk which
> is needed for overload resolution, isn't it?)
>
I've no idea why C++ required defaults last; it certainly seems wise to
avoid confusion with the positionals in Python.
> and when calling, just omit parameter when you want to
> use defaults:
> a_func(, , 3)
>
Yerch! So now you've forced all arguments to be positional? This doesn't
seem like an improvement. And it's just plain fugly.
> 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.
>
Whereas you can invariably remember their positions? I don't think so.
> Is there some contradiction in python syntax which disallows
> an easy implementation of this feature, or just nobody bothered
> with this? If former is the case, please show me why, because
> I badly need this feature in embedded python app (for
> compatibility with other language that uses such syntax) and might
> venture to implement it myself, so don't want to waste time
> if it's gonna break something.
> Or maybe it might be an idea for enhancement proposal?
>
The thing about enhancement proposals is that they are supposed to
*improve* the language. Frankly I wouldn't see this as any kind of
enhancement.
If you have a large program to translate from another language you will
probably find that a modest application of Python suffices to translate
all the calls into whatever form turns out to be required in Python.
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd www.holdenweb.com
Love me, love my blog holdenweb.blogspot.com
More information about the Python-list
mailing list