What If..... Strong Types
Don Garrett
garrett at bgb.cc
Wed Jun 19 01:11:22 EDT 2002
Peter Hansen wrote:
> Don Garrett wrote:
>
>
> It takes work to define those interfaces. In my opinion, unnecessary,
> inconvenient, and unreadable work... And Python does have private
> members, of course, for the right definition of private.
I don't think it would take MUCH work to define those interfaces. The only
addition work would be a line per member variable. However, any extra work is
some extra work.
The other limitation (can't delete, add or change out methods) limits what
you can do, but doesn't require you to do any more work. Unless, of course,
it's working around the limitations.
> Preventing modifying methods on an instance would make some of my
> automated testing really difficult, if not impossible.
Hum... that's the only specific example I've ever run across where someone
would need to switch out a method implementation at run time in production
code. Depickling and several other very nice features probably depend on it,
but they are core libraries, not general code. I draw a distinction there.
I suggest that you could create a testing subclass that overrides the
methods in questions with testing versions of the methods.
Would that work as well? As easily? In C++ or Java I'd have said that a
testing class would be to much trouble, in Python it means one line plus the
new methods that you would have to write anyway. You also have to be smart
about how class instantiation is done (the bigger problem).
Another possibility is to say that all methods are function pointers and
can be replaced with another function pointer, as long as the signiture
matches up well enough. That would still leave a fixed interface and make the
main change that I think is needed for compilation. I think.
> I don't understand the "must be declared to exist" part. If they are declared
> but not defined, they don't exist anyway. If they are defined, then they
> already exist and a declaration is redundant. Or were you using some other
> definitions of "define" and "declare"?
I mean that the class definition specifies all members that instances of
that class would contain. All instances would contain all of those members,
and only those members until they are destroyed, even if they only hold a
value of None.
> Fork a branch of Python and experiment!
Eventually, I may to exactly that! Unfortunatly, I'm spening most of my
time trying to pay the morgage (and Python helps me do that, so I feel that I
do owe time to the Python community), so I spend time trying to decide what I
would be doing if I really had the time. ;>
> I suppose, since Python is flexible and adding all these things to the
> language would tend to make it more restrictive and, well, brittle, you
> could probably call the language "Stick". :-)
>
> -Peter
More information about the Python-list
mailing list