Perhaps I am just dumb

wooks wookiz at hotmail.com
Sun Feb 10 03:22:57 EST 2002


quinn at hork.ugcs.caltech.edu (Quinn Dunkan) wrote in message news:<slrna6bord.9tv.quinn at hork.ugcs.caltech.edu>...
> 
> No, you're being too CS-PhD-y.  "poly-what?"  Yes, python is polymorphic, but
> there's no need to get all fancy-pants about it.  

You are joking right. Just in case you're not. Well no polymorphism
isn't part of my standard vocabulary. Being able to relate a Python
concept to an OO concept helps clarify the raison d'etre of said
python concept (assuming it is not obvious). I then have the option of
going off to look for an idiots guide to polymorphism to further help
my understanding.

>I suspect that neither the 2
> classes subclassed UserDict because their author didn't feel like it.  UserDict
> defines a few methods for you, and can be convenient, but you don't hafta use
> it.  I make dict-likes all the time, but rarely use UserDict, because it
> insists I have an appropriate 'data' attribute.
> 

Maybe, but we're talking about a book that aims to educate  not ones
personal coding prejudices. I still think my guess is right and
explains why userdict was not even mentioned much less used.

> The magic methods are methods that are magically called by non-method-looking
> syntax.  So len(o) actually calls o.__len__() (for historical reasons, IMO),
> and x[y] actually calls x.__getitem__(y) (since 'x[y]' is easier to type), and
> x[y] = z calls x.__setitem__(y, z) (since it's more natural looking to people
> used to infix algol-esques).
> 
> They don't have anything to do with polymorphism per se, but of course they
> make it easier, as any time you define a general-purpose widely-used method
> for your object (i.e. x[y] aka __getitem__ is widely-used so if you define it
> your object can work with any __getitem__-using code).
> 

So they are just syntatical sugar. That description would immediately
explain their raison d'etre. Shame it wasn't used. Anyway now you are
saying that my understanding of polymorphism isn't what it was so it
looks like I need to go and reread. I think I ought to understand it
as it is a fundamental OO concept which I would like to be able to
recognise when I come across it.



More information about the Python-list mailing list