Could Python supplant Java?
Paul Foley
see at below.invalid
Fri Aug 23 10:07:41 EDT 2002
On Fri, 23 Aug 2002 04:12:48 -0700, James J Besemer wrote:
> Paul Foley wrote:
>> On Wed, 21 Aug 2002 06:22:24 -0700, James J Besemer wrote:
>>
>> > Some more zealous sources claim that "polymorphism" and other OOP
>> > techniques are impossible with early binding and thus require late
>> > binding to make it possible. This is bullshit.
>>
>> Assuming the "this" that you say is bullshit is not self-referential
>> (like "this statement is false"), please explain how it can be done.
> C++ implements polymorphism in two ways.
> First off, since all variables have a known type, most member references can
> be directly resolved by knowing the object type and member name. In the case
> of name clashes, the ambiguity is resolved by using the most recent
> declaration.
> class A {
> int x;
> int bar(){...}
> };
> class B : A {
> int y;
> int bar(){...}
> };
> void foo( A a ){
> a.x;
> a.bar(); // calls A.bar()
> }
Yes, I know. But if you pass it a B instance, it ought to call
B.bar(), not A.bar(). What C++ does is Just Plain Wrong.
No sign of polymorphism there.
You only get polymorphism if you declare your member functions to be
"virtual", in which case it does late binding -- which is no help to
your argument that you don't need late binding for polymorphism.
> be distinguished if they have different argument lists. a.bar() is
> unambiguous but b.bar() is not. b.bar() is resolved in favor of the most
> recent declaration. There's a scope resolution operator to override
> defaults.
In other words, there's no polymorphism; you have to dispatch to the
right place manually...assuming you can even know what the right place
will be.
> This is all completely static.
Yes. Also completely lacking in polymorphism, so what was the point?
> To handle the more dynamic case C++ uses 'virtual' functions. This allows a
> function to access functions in subclasses it doesn't know exists.
> Declarations are like before except for the addition of a 'virtual' keyword:
Exactly so. Polymorphism requires late binding (except in special
cases, as discussed previously)
> [Implementation details are an exercise for the reader.] However, I will
> point out that there is no Python- or Smalltalk- like dictionary lookup at
> runtime.
And just what do you think your C++ vtable lookup is?
> So you can have 'true' Polymorphism without late binding.
You've failed to demonstrate that. You had to resort to late binding,
via `virtual', to get polymorphism in C++
--
For þæm se þe his cræft forlætt, se bið fram þæm cræfte forlæten.
-- Ælfric
(setq reply-to
(concatenate 'string "Paul Foley " "<mycroft" '(#\@) "actrix.gen.nz>"))
More information about the Python-list
mailing list