[Edu-sig] Does any such tutorial exist?

Kirby Urner urnerk@qwest.net
Sat, 08 Feb 2003 20:37:20 -0800


At 11:07 PM 2/8/2003 +0000, george hanson wrote:
>
> >
>Thats true but hmm, it wasnt my original intention.
>(It may be because I remember how we were taught long ago,
>using structured programming flowcharts. But with most universities teaching
>Java as a first language, things may have changed.)
>
>Now that you pointed it out, I might have to look into it and reconsider.
>
>
>Cheers
>George

Yeah, I think the OOP thing should be introduced early, so that newcomers
don't have to recapitulated the "paradigm shift" from procedural.   It's
kinda like how countries today go straight to cell phone, skipping the
whole land line phase of infrastructure development.

Along the same lines, I think a basic intro should give at least a few
examples of passing functions as parameters.  For example:

 >>> def sum(f,alist):  # first argument is some function
         sum = 0
         for x in alist: # 2nd argument feeds f
            sum += f(x)  # accumulate f(x1) + f(x2) + f(x3)...
         return sum

 >>> def sqr(x): return x * x

 >>> sum(sqr,range(5))
30
 >>> 0 + 1 + 4 + 9 + 16
30

Of course the more Pythonic way to express this would be:

 >>> reduce(add, [sqr(i) for i in range(5)])
30

but I gather you're trying to keep this kind of syntactic sugar
for latter.  Once students know the basics, then you can explain
list comprehensions and such using equivalent "long hand"
syntax, i.e. decode these more compressed forms in terms of
what's already understood.

My thought is if you get this kind of flexibility in early (e.g.
functions might be parameters to other functions), it'll spark
students to explore more.

I think the OOP thing is important because even at the basic level,
expressions like "aaa".upper() make sense only when you understand
that "aaa" is an object.  Likwise 1 .__add__(2) is legal Python --
although this I *would* consider more advanced syntax (but it
builds on early OOP understanding).

Kirby