[Edu-sig] Transition to OOP

kirby urner kirby.urner at gmail.com
Tue Feb 9 04:02:34 CET 2010


On Mon, Feb 8, 2010 at 3:33 PM, David MacQuigg <macquigg at ece.arizona.edu> wrote:
> csev wrote:
>>
>> On Feb 5, 2010, at 9:31 PM, kirby urner wrote:
>>
>>>
>>> What I'm not seeing here is any plans to venture into user-defined types
>>> i.e. rolling your own classes.
>>>
>>
>> I am indeed tempted into user-defined types.  I actually teach OO Python
>> in my App Engine course because it is necessary there.  And Think Python has
>> a nice chapter.  But my problem is find a use case that drives me there in
>> "exploring data" - I see using objects all over the place - but making your
>> own does not yet feel part of the data narrative.
>>
>
> Unless the course is *about* programming, I would delay user-defined classes
> until you really feel the need.  Then there is no need to motivate the extra
> complexity.  The benefits will be apparent.  I see that Mathematics for the
> Digital Age does show an example of a class on page 88, but I note that this
> is anecdotal information, not something the students are expected to learn.
>

Yeah, I think I'm ready to throw in the towel on this one.

I know there's this Standard Library class, an XML parser or something,
that you subclass and run against an HTML file say.  You write methods
for if it's a <div> tag, a <p> tag or whatever (<span></span>?).  You
basically script out this catcher's mitt, that listens on tags.

OK, so I went looking for it in urllib2, and gave up.  Why?  Because
in talking to my company president friend, who hacks a LAMP stack
and filters through HTML (energy biz focus), I learned that people
use Beautiful Soup, and you don't need to know subclassing for that.

So for Dr. Chuck's specific book and application, I'm thinking he's right
to be skeptical and you're right to back him up.

Regarding Litvins pg. 88, yeah that's somewhat anecdotal in that
there's a reduce function mentioned, but not provided.  It'd normally
involve GCD (we're reducing to lowest terms by factoring out the
greatest common denominator) but that function doesn't come
until the RSA section at the end of the book.  So this is not
necessarily the proper place to start in with the basics of OO.

So I'd posit something more like the gentle introduction to Classes
on Wikieducator, that simple intro at the end (PSF_Snake demo).
This would be in a different book in a different course, probably
with MFDA still on ahead for a lot of those taking it.

A prime motivation for user defined types is of course operator
overloading (what page 88 illustrates).  This is a math course
so when we add 3/4 and 5/8, we'd like to use syntax as natural
and familiar as (3/4) + (5/8), as this reminds us we're working
with ordinary Fractions (using an executable notation).

Unlike many languages, Python makes this feature unusually
easy (Ruby too), so we learn just enough about OO to get
that working.  We're not in MRO country, not doing multiple
inheritance.  We're just figuring out what makes Rational
Numbers tick, which is why a skilled teacher might use Litvins
page 88 as a fun touch stone.  We get to it already knowing
about GCD, as Euclid's Method came earlier, plus we've been
through all that Dog, Monkey, Mammal stuff and don't find
the notation that alien any more (yet we're not Python black
belts, would still need more CS, then maybe Java, so many
paths possible).

Re MFDA 2nd edition pg 89:

Note how f1 + f2 i.e. f1 .__add__(f2) is an argument to the
format function and being fed to a string.  The + sign is
triggering the __add__ in other words (the only operator
implemented on pg. 88, more a sketch than working code).
Not complaining.  MFDA is a perfectly legitimate slice through
a vast topic space.  Design decisions were made.  Not
much use of a turtle either, or polyhedra.  Can't do everything
in one slim tome.  That's why we need (and have) lots of
books, more on the way, some of 'em wikis.

Anyway in this case it's not that it's a course about
programming, so much as it's a course about "types of math
object" and what makes them tick.  Vectors, Polyhedra,
Polynomials... those things that they teach you about
with or without computers, on the scene long before OO.
Some courses just take advantage of some newer tools.
Mathematica?  GameMaker?  Depends on the catalog.

A Computational Thinking class is not identically a
Bioinformatics class, which latter might be more about
filtering through reams of data (or a Shakespeare play),
a perfectly valid and reasonable use of a scripting
language, one of the best use cases out there.  Python
is very appropriate for this, as the text cleverly shows.

So yeah (throwing in the towel) maybe there's no great
use case for getting into user-defined types.

Here's a valid reason to branch off an excellent beginning
of How To Think Like a Computer Scientist, and to take
it in some other direction.  More with Regular Expressions
perhaps, talking to databases.  A tree of alternatives
naturally grows here.

That's what open source curriculum writing should
encourage, not everyone rewriting the same book.  We'll
go off in our different directions and compare notes where
paths cross.

> Fast forward six years.  I'm helping with a graduate course on cryptography,
> and for the first time this semester felt the need for a class definition.
>  I wrote a function to model an LFSR.  Then it became apparent that I need
> more that just this one function, so I wrote a class definition.  You can
> see the two side-by-side at
> http://ece.arizona.edu/~edatools/ece596c/LFSR.html.
>
> Even if the class will now do everything the function does and more, it is
> still nice to study the function first, understand how the LFSR works, then
> look at the more complex class definition.
>

Coolness.  Fun to think about crypto some more.

I did a bunch of pages on crypto, starting with an implementation of Blowfish,
linking to Neal Stephenson's book Cryptonomicon.  I went on to provide a
gentle build up to RSA that's pretty comprehensible.

http://www.4dsolutions.net/ocn/crypto0.html

If you check, you'll see I stay at the function level in the first section,
but have some Permutation class going already by section two.  This
isn't their first exposure to Python, lets assume.  We're more like at
the end of MFDA, when they're ready to tackle RSA -- which is what
I get to as well, maybe by a different route.

Lots of teachers with web sites like this, showing off different ways
to parse out the topics.  Not saying the way I'm providing is best or
only, just another.  I made lots of cool graphics, mostly with POV-Ray.
Even embedded a Java applet or two (I take some pride in my work,
as one would hope).

Now Patrick, my company president friend, does roll his own classes
i.e. he's found the programmer's need for them.  He uses the unit
testing framework.  He likes to encapsulate.  But when he paws
through HTML files, I think he's basically just using beautifulsoup,
why reinvent that wheel?

Sounds like we're all in agreement?

Conclusion:  a lot depends on what use cases you're wanting to
cover.  Too many use cases to cover them all.  So pick and choose,
teach accordingly.  Sounds like a plan.

Kirby Urner
4D Solutions
Portland, Oregon


> ************************************************************     *
> * David MacQuigg, PhD    email: macquigg at ece.arizona.edu   *  *
> * Research Associate                phone: USA 520-721-4583   *  *  *
> * ECE Department, University of Arizona                       *  *  *
> *                                 9320 East Mikelyn Lane       * * *
> * http://purl.net/macquigg        Tucson, Arizona 85710          *
> ************************************************************     *


More information about the Edu-sig mailing list