Optional parameter object re-used when instantiating multiple objects

Rick Giuly rgiuly.group at yahoo.com
Wed Nov 19 08:41:57 EST 2008


Thanks to all for your replies

All things considered, I vote for evaluating the arguments at runtime
(each time the function is called). Good reasons for this have already
been mentioned so I won't repeat them. A programming language is a
user interface of sorts. (Pretty much all languages are logical so
"correctness" is not what I'm meaning to discuss - I'm thinking about
usability.) Python provides, for the most part, an *excellent* user
interface to the programmer. Why not make it even "better" by
evaluating the arguments each time the function is called? It will be
harder to change the language 10 years from now, so why not change it
now?

(By "better" I mean that over many years of time programmers will be
more productive because the language will be learned a bit faster with
a fewer surprises - and still retain its power.)

-Rick

On Nov 16, 10:28 pm, "Chris Rebert" <c... at rebertia.com> wrote:
> For the Nth time this year that this has come up, I'll point out yet
> again that this issue has already been discussed to death before:
>
> [Python-ideas] proto-PEP: Fixing Non-constant Default Argumentshttp://mail.python.org/pipermail/python-ideas/2007-January/000121.html
>
> [Python-3000] pre-PEP: Default Argument Expressionshttp://mail.python.org/pipermail/python-3000/2007-February/005704.html
>
> Result: Evaluating the arguments at runtime rather than
> definition-time was deemed too magical; the backward compatibility
> issues make changes unlikely; it's hard to find an acceptable syntax.
>
> But hey, if some people want to have another go at it, best of luck.
>
> Cheers,
> Chris
> --
> Follow the path of the Iguana...http://rebertia.com
>
> On Sun, Nov 16, 2008 at 8:11 PM, alex23 <wuwe... at gmail.com> wrote:
> > On Nov 17, 12:27 pm, Steve Holden <st... at holdenweb.com> wrote:
> >> If multiple statements are needed to perform the
> >> argument initialization, how would you then propose the problem should
> >> be solved?
>
> > Why, with another function of course!
>
> > def f(x, y=`f_arg_computation(x)`): ...
>
> > Or my personal favourite:
>
> > def f(x, **`f_arg_computation(x)`): ...
>
> > Seriously, though, I agree with Steve; the function body -is- the
> > place for computation to occur.
> > --
> >http://mail.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list