Re: myfile.py: a Class wrapper for file objects & prompting readlines()

Steven D. Majewski (sdm7g@elvis.med.virginia.edu)
Thu, 3 Mar 1994 19:46:13 -0500

On Mar 2, 10:52, Guido.van.Rossum@cwi.nl wrote:
>
> Ooohh, Steve! The line
>
> > apply ( self.__class__.__bases__[-1].__init__, (self,)+args )
>
> just hurts my eyes. Classes are *designed* to have a static
> inheritance pattern. It is not a sin to repeat the name of the base
> class explicitly when extending a method of the base class -- quite to
> the contrary, this is recommended practice!
>
> What you do will major screw up any class derived from
> SimplePromptFile. The expression "self.__class__" is by definition
> the most derived class, *not* the class containing the line.
> Therefore self.__class__.__bases__[-1] can be *anything*...
>

As I discovered.

Yeah. That part of the code was pretty ugly. But for a quick hack,
I didn't want to spend the time to go back and do it RIGHT - *AND*
I thought someone else might learn from my mistakes too, - so the
note drawing attention to the goof!

As I noted in previous threads: I haven't usually had much use for
inheritance ( as opposed to ADT or interface inheritance ) and
even as I've been learing to make more use of it, it is seldom
very deep. ( I've seen someone in comp.object mention a study
that said that average depth of inheritance is only about 2.2 )
This was the first time I actually had a class that looked like
it was likeyly to be usefully extended 4 or 5 deep. ( And, like
I said: I blew it! )

>
> Here's an exercise: practice programming for a while without using
> self.__class__, self.__dict__, or <class>.__bases__. Come to think of
> it, __main__ and __name__ are also out, *except* to differentiate
> between a script and an imported module. All these attributes are
> there mostly for debuggers and other tools, not to pervert Python into
> Scheme!
>

You've got me pegged correctly there. The problem is that what I
REALLY want is Scheme with objects build in at a lower level
rather than added on top, with modules and a algebraic syntax.
( Hmmm... sounds kinda like Dylan ... )
However, one thing I've learned from watching Python grow, and
from listening in on the Syntax bickering on Comp.lang.dylan is
that the best thing about Lisp-ish syntax is that it is so simple
it's impossible to screw-up and get it wrong. An algebraic or
algol-ish/C-ish (whatever) syntax, on the other hand, has so
many interactions ( as the whole scope discussion shows ) that,
clearly, not all things are possible, and current decisions
may bind you in the future. ( An example: one of C's inventors
admitted in a paper that one of the things he would have liked
to go back and change was to change pointer dereferencing '*'
to a POSTFIX operator. That one (incompatable) change would
have eliminated all of those thousands of man hours of
confusion and indecision when trying to figure out how to
express: pointer to a function returning poniter to an int,
or some such. )

Seriously: One of my current projects ( the one that used the
collect() function that STARTED the whole Lambda thread )
involves prototyping and comparing S+, Matlab, Maple, XLisp-Stat
( and maybe Python, if I can ever get the X11 stuff built and
working ) as an extendable platform for some of our analysis
and statistics. Sometimes I find myself writing in a pseudo-code
that *looks* like python but has scheme semantics.

> (I wonder if I should've made a distinction between these and, say,
> __init__ and __del__ which are perfectly legal to use...)
>

Yeah. At one time I thought I saw a rule there, but then __init__, etc.
blew that away. Also, func.func_globals, etc. are also counter
examples.

- Steve Majewski (804-982-0831) <sdm7g@Virginia.EDU>
- UVA Department of Molecular Physiology and Biological Physics