[Edu-sig] Re: Integration correction

Scott David Daniels Scott.Daniels at Acm.Org
Wed Mar 30 01:29:12 CEST 2005

ajsiegel at optonline.net wrote:
> From: Kirby Urner <urnerk at qwest.net>
>>def g(x):  return x*x
>>>>>g(0, 3)

> My resistance to decorators is not unrelated to the fact that I don't 
 > seem capable of getting my mind around them.
 > I do find it quite disconcerting that the arguments "g" is expecting
 > cannot be ascertained in the normal manner - that is by looking
 > at "g" for the arguments it is expecting.  Ouch, ouch, ouch.

There is a difference between generators and functional programming.
This example is, I think a bit of a misuse of generators: you should be
producing the "same" function somehow.  So generators that keep a
cache of answers to slow questions, generators to do logging, and
such like make a lot of sense to me.  I think the example above is
better written as:

     def g(x):
         return x*x
     f = simpson(g)
     f(0, 3)

It is an example of functional programming, and generators are
always about functions of functions, but they are not always the
right way to express it.  Functional programming is often hard
to wrap your head around.  I am not sure generators add to the
problem, but generators just cannot be used in anything but a
functional way.

> I *particularly* dislike decorators in the context of teaching/learning.  
> Something that is relatively straight forward as executable pseudo-code
> becomes fancy/schmancy programming.

Well, one natural progression is values, expressions, variables,
functions, then one of recursion, objects, or functions of (and
returning) functions.  I would think generators belong fairly soon
after functions of functions.

--Scott David Daniels
Scott.Daniels at Acm.Org

More information about the Edu-sig mailing list