[Edu-sig] RE: Integration correction

Guido van Rossum gvanrossum at gmail.com
Wed Mar 30 02:39:17 CEST 2005

> And with a decorator:
> def simpson(f):
>    def defint(a,b,n=1000):
>      [...]
>    return defint
> @simpson
> def g(x):  return x*x
>  >>> g(0, 3)
>  9.0000000000000036

No matter how cool decorators are, I don't think this is a good
example of how to use them. The function g(x) is a perfectly good
function in its own right, and I don't think it ought to be tied as
closely to the integration routine. Also, adding the nested-function
boilerplate to the integration routine distracts from the numeric
code. nd finally, it's somewhat confusing to see g() defined as a
function taking (x) as its sole argument and then used as the
integrator function taking (a, b) as arguments.

The way this would be done before decorators is just plain better!

--Guido van Rossum (home page: http://www.python.org/~guido/)

More information about the Edu-sig mailing list