feature request: parameter functions

Peter Hansen peter at engcorp.com
Sat Aug 18 02:12:50 EDT 2001


"Steven D. Arnold" wrote:
> 
> A feature idea for Python.  
[...]
> Some example code:
> 
>     def foo(a, b, c=myfunc(c)): [...]
> 
>     def myfunc(param):
[...]
> All this is really no different than code like this:
> 
>     def foo(a, b, c=None):
>         c = myfunc(c)
> 
> ...but it's cleaner, especially for functions with many parameters.

Actually, no it's not.  That is to say, the definition of
"cleaner" is obviously a matter of personal choice here.  What
you've proposed looks *really* ugly to me, doesn't look at all
Pythonic (IMHO), and is not only less easy to read but is
probably less maintainable.  

At least with the second approach, one can write some clear
comments above or next to the call to myfunc() explaining
why one needs to massage the data this way.

The entire pattern you are proposing here is one I don't
know if I've ever had to use, and may never have seen before.
Maybe I'm just dense, but I've managed to program all this
time without ever writing "parameter massaging functions"
like this.  What have I been doing wrong? (Rhetorical question :-)

Not to mention that the second approach doesn't require still
more syntactically sugary changes to Python, which is 
_just_fine_as_it_is_!

-- 
----------------------
Peter Hansen, P.Eng.
peter at engcorp.com



More information about the Python-list mailing list