[Edu-sig] Retrospective: Our Open Source class including Python
Kirby Urner
urnerk at qwest.net
Mon Jul 19 20:19:25 CEST 2004
> Since operations in Python are normally accessed via built-in operators
> versus explicit method calls, and since you don't normally subclass int or
> float, I would not have led off my discussion of types and objects by
> using int and float as examples. Those types are more the exception than
> the rule, as far as how you use them.
>
My thinking was colored by the parallel mathematics curriculum, wherein we
start with natural numbers, then progress through integers, rationals, reals
and complex. At each stage, a new type of number is introduced to address
limitations of the earlier types.
I'm thinking a good way to talk about types with kids is to go over this
experience of gradually extending the number types in grade school, then
talking about how "just numbers" is insufficient -- we need a date/time
type, a string type, and so on.
Note: When I developed a mod 7 int-like class, I didn't start by
subclassing int, only by overloading some operators. My feeling is in
subclassing int, I'm committed to overloading *all* the operators to make
them consistent with mod 7 -- too big a commitment.
> I think leading off with the Mammal class, hippo instance would have been
> more clear, and then afterwards say, "oh by the way, *everything* is an
> object, even int. Look at this:
>
> >>> (3).__add__(4)
> 7
>
> See, you can even call methods on 3."
>
That's good notation. I'd always put a space after the 3, as in 3 .__add__,
but the paren style is better.
> Good stuff. I liked the scissors-paper-rock object lesson on why you want
> access to the source! With the youth I am teaching, I'm trying to use
> extending (and possibly "cheating") on a multi-player game as motivation.
> He/she who can code gets the advantage, knows the hidden commands that
> refuels your ship, etc.
>
> David H.
Or that elects your president? :-D
Kirby
More information about the Edu-sig
mailing list