Unification of Methods and Functions

Donn Cave donn at drizzle.com
Sun May 23 12:44:27 EDT 2004


Quoth David MacQuigg <dmq at gain.com>:
| On Sat, 22 May 2004 18:28:33 -0000, "Donn Cave" <donn at drizzle.com>
| wrote:
[1 page intro to Python OOP]
...
| This is OK for the first example.  I would leave the __init__ methods
| to the second example, but either way it will take about 8 pages to
| comfortably explain OOP ( maybe ten if I include the "robust
| programming" examples that JM says I must ).  I would like students to
| understand Python at the level they can follow what is going on in a
| real program, and maybe write a few classes themselves.

That 1 page is enough.  The other 7 pages should be elaboration of
the language elements introduced on the 1st page.  That will definitely
work for real programs.  It is possible to write real programs in
idiomatic Python!

My first (and only) programming course was a half quarter of FORTRAN,
for numerical and statistical data processing in natural sciences.
The instructor chose to omit a number of features, including formatted
output if I remember right.  FORTRAN is not a complicated language, and
formatted output is really a mainstay.  Later I learned formatted output
on my own before I really went very far with programming, but I didn't
have to wrestle with it while learning the language.  Good idea, reduce
initial exposure to the really minimum essentials.

|> Then I would go over that, showing what happens and why, until the
|> concepts introduced above seem to be clear for everyone.  That would
|> conclude my treatment of classes.  As an elementary language, there
|> are some slightly hard things to learn about Python, but this isn't
|> going to be one of them unless you make it hard.
|
| If you are saying we can totally ignore the different method forms, I
| think you are wrong.  Bound and unbound methods, for example, will be
| needed in almost any sizable program.  The need for static methods
| will arise when the student first writes a method that needs to work
| without a current instance.

I have never needed to write a method that works without a current
instance.  Never, in a decade of using Python.

| The example I showed is not intended to explain method binding, and I
| would not use it in an introduction to OOP.  It probably won't even be
| "stumbled upon" in a normal program.  I posted it only to show that
| even experts can get confused by Python's binding syntax.  Are you not
| confused by this example?

No, but by the time such a thing would have occurred to me at all -
to poke a function into a class via other means than "def" - I had
a fairly solid ground in the mechanics of the language.  I may have
struggled with it, may have even experienced some frustration, but
not exactly confusion or profound surprise.

The very fact that you have set out to teach people a language that
you find confusing and nonsensical, when the language has a devoted
following and is wildly popular with new users in particular, should
give you pause.  Do you want your students to end up like you?

	Donn Cave, donn at drizzle.com



More information about the Python-list mailing list