Unification of Methods and Functions

James Moughan moughanj at tcd.ie
Sat May 22 14:50:18 EDT 2004


David MacQuigg <dmq at gain.com> wrote in message news:<9hgpa0d2iq5bb2ko4sngs5i6v4og90vqej at 4ax.com>...
> On 19 May 2004 23:26:38 -0700, moughanj at tcd.ie (James Moughan) wrote:
> >David MacQuigg wrote:
> >> I've made your program, Animals_JM.py at
> >> http://ece.arizona.edu/~edatools/Python/Exercises/ the next example
> >> *after* Animals_2.  The topic of techniques to make a program robust
> >> and maintainable is worth a whole chapter, but it would be a
> >> distraction in the introductory chapter.
> >> 
> >> I would still like to see a way to gain the benefits of both Animals_2
> >> and Animals_JM in one program.  My attempts to follow up on
> >> suggestions in this discussion have only added complexity, not
> >> improved the program.
> >
> >Simple method - choose a different example.  However, you do not
> >appear to be open to this suggestion.
> 
> If I were not open to suggestions, I would not be spending all this
> time patiently extracting the good suggestions from this long thread,
> and putting up with dogmatic statements and personal attacks.  I could
> repond by saying most of what I'm reading is hot air, but that would
> be equally provocative.  Let's see if we can bring this to a better
> conclusion.
> 
> I like your example, but not as a *substitute* for Animals_2.  It's
> just too complex for non-CIS students at this point in the course.  I
> think I understand your concerns about Animals_2.  I think the best
> way to deal with those concerns is not by complicating the example, or
> by taking out everything that could lead to problems, but rather by
> pointing out the problems, and showing subsequent examples that fix
> those problems, even at the expense of more complexity.
> 
> If you have a simple all-in-one alternative to Animals_2, show me.
> 

Again, clearly I have not communicated myself well - I mean a
*completely* different example to the entire Animals approach.  The
difficulty with writing a good Animals-type example comes from the
things which it is trying to do, which aren't especially well
expressed by a class-heirarchy.

Why not just take one of your earlier program examples, show the
students what it looks like when object-oriented, then extend the
class(es)?

As I've mentioned, I don't like my example *at all* for your teaching
purposes, and I'm not suggesting you use it.  It was simply to
illustrate that there is another method of doing things, and what the
original problems were.  (A good solution to the Animals 'problem'
would be simple, it just wouldn't demonstrate any of the things you
want to show.)



> 
> We also need to make sure we include *all* children of Reptile in the
> new numReptiles function.
> 
> class Reptile(Animal):
>    -numReptiles = 0
>    def numReptiles():
>       return ( Reptile._numReptiles +
>          Snake.numSnakes() + Lizard.numLizards() )
> 
> Oops.  We forgot Geckos !!
> 
> To avoid these errors in programming, we may need a function that
> automatically searches for subclasses, and calls their num functions.
> I'm not sure how to do this without making it excessively complex.
> Suggestions will be appreciated.
> 
> -- Dave

Hmm, I think perhaps I like your original example better than this.
:-\   It's a bit like treating a cut throat with a tourniquet.

Searching the subclasses will AFAIK still require some kind of
metaprogramming, which is not too suitable for a 4-hour beginner
course on OO.



More information about the Python-list mailing list