From: gga Date: 2005-10-24T14:47:01+09:00 Subject: Re: A comparison by example of keyword argument styles Yukihiro Matsumoto wrote: > Hi, > > Right syntax is > > def function(a, b, c, d:, e: 1, f:) > end So if I have default values on both positional and named parameters, it would look like this? def function( a, b = 2, c = 1, d: 1, e: 2, f: 3) end Hmm... The reason why pythonist don't need the distinction between named/positional parameters is that exposing an api also comes down to common sense. Let's see if an example works as intended. To make sure it does, I *won't* say which parameters I expect to be positional parameters in my api and which one's I already locked. I won't provide any rdocs, either. Let's see if you guess... def texture( name, smin, tmin, smax, tmax, filter = 'gaussian', filtersize = 0.5 ) end Looking at the above, which parameters would you call by name and which ones by position? Spoiler below... If you said filter and texture as the named parameters, python's method probably is on to something. IMO, parameter default values are so very tighly linked to named parameters that I almost see no distinction most of the time. I often don't see positional arguments with defaults. The above function, btw, is not taken from python. It is taken from probably the oldest api in existance that has never had a dramatic syntactic change (and where I first saw what named parameters could do): Renderman. This 3d shading language api has lasted over 20 years without a change and afaik, they were the first or one of the first languages to have named parameters. And yes, before someone points it out, the texture() call in renderman is more complex than the above, as it automatically reads from globals and also works with a single parameter and worse, it is overloaded based on its return values, making it also a perfect counter-example to the idea of the rule of positional parameters not having defaults. Let's see how a python guy would solve this issue... def texture( name, smin = $s, tmin = $t, smax = $s + $ds, tmax = $s + $dt, # named parameters: filter = 'gaussian', filtersize = 0.5 ) I added only a single comment... in the middle of the function definition. Do I really need the interpreter to enforce the above and have to rewrite all previously written functions to support named parameters now?