Python was designed (was Re: Multi-threading in Python vs Java)

C

Chris Angelico

I don't know if I want to step into the flames here, but my understandinghas always been that in the absence of polymorphism the best you can do is"object based" programming instead of "object oriented" programming.

Object oriented programming takes things further, most significantly by introducing the idea that the object reference you are referencing might be a run time dependent sub-class. Even Python, which isn't strongly typed, manages polymorphism by allowing the self argument to a sub-class of the method class.

What you've said here is that "without polymorphism, you can't have
polymorphism". :)

The OS/2 PM with SOM (System Object Model) classes does give
polymorphic functionality; here's a bit of an example:

(Reference: http://www.markcrocker.com/rexxtipsntricks/rxtt28.2.0299.html
- class hierarchy, standard classes only)

Part way down you'll see WPFolder. It's a subclass of WPFileSystem
(aka "stuff backed by the disk" as opposed to abstract objects), which
is a subclass of WPObject (aka "stuff you can see and click on"),
which is a subclass of SOMObject (aka "stuff"). The WPFolder class
defines a whole pile of functionality, and its code is all stored in
some library somewhere, as a binary on the disk. Well and good.

Now look at the WPRootFolder class. It's a subclass of WPFolder and
adds a few extra bits and bobs designed for the root of any particular
drive (OS/2 uses an MS-DOS style of drive letters for volumes, rather
than a Unix-style mount points) - menu items for formatting the drive,
getting extra info perhaps, whatever. But most of its functionality
comes from WPFolder.

When a WPFolder method is called on a WPRootFolder, the code has to
handle the fact that it's working with a subclass of that object. As
long as the proper SOM boilerplate is maintained correctly, the
WPFolder code won't even be aware that it's operating on a
WPRootFolder. That's polymorphism, and it's all done in a completely
cross-language way :)

(There are additional complications, as it's possible for a subclass
to WPReplaceClass (I'm probably misremembering the function name)
itself into the position of the parent class, which messes up the
hierarchy a bit - it still all works, but it's less clean to describe.
Most things work the way I'm describing.)

ChrisA
 
P

Peter Cacioppi

What you've said here is that "without polymorphism, you can't have
polymorphism". :)

Respectfully, no. I refer to the distinction between object based and object oriented programming. Wikipedia's entry is consistent with my understanding (not to argue by wiki-authority, but the terminology here isn't my personal invention).

Your example of "polymorphism in a non OO" language makes my tired head hurt. Do you have a clean little example of polymorphism being mocked in a reasonable way with pure C? There are many nice object-based C projects floating around, but real polymorphism? I think you can't do it without some bizarre work-arounds, but I'd be happy to be shown otherwise.
 
C

Chris Angelico

Respectfully, no. I refer to the distinction between object based and object oriented programming. Wikipedia's entry is consistent with my understanding (not to argue by wiki-authority, but the terminology here isn't my personal invention).

Yep, but your definition of object oriented programming is
fundamentally based on support for polymorphism, and your opening
statement said that it's impossible without polymorphism :)

Anyway, what I sought to prove was that polymorphic object oriented
code can be written in C or any other language.

ChrisA
 
R

rusi

Object oriented programming takes things further, most significantly by introducing the idea that the object reference you are referencing might be a run time dependent sub-class. Even Python, which isn't strongly typed, manages polymorphism by allowing the self argument to a sub-class of the method class.

Yes and the reference I earlier gave was just for that:
http://lwn.net/Articles/444910/

Ironically he describes the whole 'polymorphism-in-C' infrastructure there but does not call it that.
The first line however in the sequel article http://lwn.net/Articles/446317/
does just that. Heres the quote:
 
R

rusi

introducing the idea that the object reference you are referencing might be a
run time dependent sub-class. Even Python, which isn't strongly typed,
manages polymorphism by allowing the self argument to a sub-class of the
method class.


Yes and the reference I earlier gave was just for that:
http://lwn.net/Articles/444910/

Ironically he describes the whole 'polymorphism-in-C' infrastructure there but does not call it that.

The first line however in the sequel article http://lwn.net/Articles/446317/
does just that. Heres the quote:

I would be a bit remiss if I left it at that -- yeah Mark is clueless about his history and philosophy. However the general usage of the word polymorphism in the OOP community is not much better.

Cardelli and Wegner:
http://lucacardelli.name/Papers/OnUnderstanding.A4.pdf
give a conspectus of the field. Especially section 1.3 shows that the word can mean one of 4 very different and unrelated ideas.

OOP aficionados think one of them to be the only one.
 
P

Piet van Oostrum

Peter Cacioppi said:
Respectfully, no. I refer to the distinction between object based and object oriented programming. Wikipedia's entry is consistent with my understanding (not to argue by wiki-authority, but the terminology here isn't my personal invention).

Your example of "polymorphism in a non OO" language makes my tired head hurt. Do you have a clean little example of polymorphism being mocked in a reasonable way with pure C? There are many nice object-based C projects floating around, but real polymorphism? I think you can't do it without some bizarre work-arounds, but I'd be happy to be shown otherwise.

The first C++ compilers were just preprocessors that translated into pure C code, which was then compiled with a C compiler. The resulting intermediate C code would be an object-oriented program in C. IIRC, the C code was reasonably clear, not really convoluted, so you would have been able to write it yourself.
 
R

rusi

Yes, well clearly we are not "having the same thoughts", yet the
purpose of the academic establishment is to pin down such terminology
and not have these sloppy understandings everywhere. You dig?

Heh Mark I am really sorry. I think this is the third or fourth time that I say something to which you reply with such egregious rubbish -- parsing has something to do with card-punches?!?! Yeah like python has something to do with the purple shirt I am wearing -- that a dozen others jump at you with a resounding 'Cut the crap!'

Well speaking for myself, I know I speak more wisely sometimes and more stupidly at others and I would wish my penalizers to calibrate the punishment to the crime.

Likewise here. I certainly 'dig' your passion to clean up the 'sloppy understandings everywhere' and would only wish for you the sanity of more knowledge of the subject before you begin to hold forth.
 
M

MRAB

Heh Mark I am really sorry. I think this is the third or fourth time
that I say something to which you reply with such egregious rubbish
-- parsing has something to do with card-punches?!?! Yeah like python
has something to do with the purple shirt I am wearing -- that a
dozen others jump at you with a resounding 'Cut the crap!'

Well speaking for myself, I know I speak more wisely sometimes and
more stupidly at others and I would wish my penalizers to calibrate
the punishment to the crime.

Likewise here. I certainly 'dig' your passion to clean up the 'sloppy
understandings everywhere' and would only wish for you the sanity of
more knowledge of the subject before you begin to hold forth.
I learned a new word yesterday: ultracrepidarian. :)
 
M

Mark Lawrence

Heh Mark I am really sorry. I think this is the third or fourth time that I say something to which you reply with such egregious rubbish -- parsing has something to do with card-punches?!?! Yeah like python has something to do with the purple shirt I am wearing -- that a dozen others jump at you with a resounding 'Cut the crap!'

Cut the crap, cut the bollocks more like. I am of course using the term
in the context described here
http://en.wikipedia.org/wiki/Sex_Pistols#Never_Mind_the_Bollocks

--
Roses are red,
Violets are blue,
Most poems rhyme,
But this one doesn't.

Mark Lawrence
 
P

Peter Cacioppi

The first C++ compilers were just preprocessors that translated into
pure C code ...

I agree with this.
the C code was reasonably clear, not really convoluted, so you would have
been able to write it yourself.

I disagree with this. My sense of C is that IF you are relying on preprocessors to do sophisticated things, THEN you are not writing clear C code. Theimplementations I've seen of polymorphism-of-structs in C are quite ugly to my eyes, and make me grateful C++ was invented.

OTOH, I've seen object-based C development projects (I.e. where you could tell what function was being called at compile time) that are quite readable.. It requires coding discipline (as does readability in any language).

We might just be arguing over the definition of "readable" here. I have been told that my standards of readable are unreasonable, so perhaps I'm in the wrong here. That said, I'm just glad true OO languages exist, especially Python.

All hail Guido.
 
M

Mark Janssen

Heh Mark I am really sorry. I think this is the third or fourth time that I say something to which you reply with such egregious rubbish -- parsinghas something to do with card-punches?!?! Yeah like python has something to do with the purple shirt I am wearing -- that a dozen others jump at you with a resounding 'Cut the crap!'

You feedback is respected. However, you haven't included in your
analysis that you have a closed group here of Python aficionados. I
invite you to take a look at
http://c2.com/cgi/wiki?TypeSystemCategoriesInImperativeLanguagesTwo
before you continue to issue insults.
Likewise here. I certainly 'dig' your passion to clean up the 'sloppy understandings everywhere' and would only wish for you the sanity of more knowledge of the subject before you begin to hold forth.

Talk to me after you've finished your assignment.
 
T

Terry Reedy

Even Python, which isn't strongly typed,

Python objects have a definite type/class. It is fixed for instances of
builtins. If that is not 'strong', the word has no meaning.
manages polymorphism by allowing the self argument to a sub-class of the method class.

???
 
M

Mark Lawrence

I don't know if I want to step into the flames here,
Even Python, which isn't strongly typed

Yeah right.

--
Roses are red,
Violets are blue,
Most poems rhyme,
But this one doesn't.

Mark Lawrence
 
P

Peter Cacioppi

My bad, Python is dynamically typed, but also strongly typed.

But I still say it has language features that specifically support polymorphism, which is why true OO can be developed in Python in a readable way.
 
N

Ned Batchelder

You feedback is respected. However, you haven't included in your
analysis that you have a closed group here of Python aficionados. I
invite you to take a look at
http://c2.com/cgi/wiki?TypeSystemCategoriesInImperativeLanguagesTwo
before you continue to issue insults.

I'm interested to learn more about your ideas, but that wiki page is not
going to help much. It's a chaotic back-and-forth, with no attribution,
so it's impossible to know who is saying what. Except that it devolves
into the same frustrated confusion, and then insults that this thread
has, so I can tell: those trying to understand are frustrated, and Mark
starts insulting people. "Hitler!": what does that mean??

Mark, if you want people to understand you, you have to get your facts
straight, you have to explain yourself clearly, and when people don't
understand, you have to not resort to insults. Perhaps you are a
misunderstood genius, I can't tell for sure. So far it just looks like
you are making sweeping over-generalizations based on insufficient
understanding of the current and past complexities of the field.

Read and listen more. Write and say less.

--Ned.
 
E

Ethan Furman

Read and listen more. Write and say less.

Mark Janssen has no interest in learning. From a thread long-ago:

Mark said:
Ethan said:
Mark said:
Really?

--> int="five"
--> [int(i) for i in ["1","2","3"]]

TypeError: str is not callable

Now how are you going to get the original int type back?

Mark Janssen, you would increase your credibility if you actually *learned*
Python.

Thank you, I actually knew it and was feigning ignorance for a good
reason -- where is this magical "assignment stack" which remembers
what int was originally bound to after I rebound it myself?

As you can see, if caught out he claims he was feigning ignorance, but then immediately shows the ignorance is real.

I take some solace in him not being a profane troll, as some in the past have been.
 
R

Roy Smith

Peter Cacioppi said:
OTOH, I've seen object-based C development projects (I.e. where you could
tell what function was being called at compile time) that are quite readable.

If you can tell what function will be called by looking at the code,
it's not object oriented enough :)
 
S

Steven D'Aprano

Anyway, what I sought to prove was that polymorphic object oriented code
can be written in C or any other language.

The proof of this is that any Turing-complete language can simulate any
other language. Obviously the *difficulty* can vary, but any sufficiently
expressive language can be used to write an interpreter for some other
language which gives you the results you want.

I'm not just talking hypothetically here. Python is polymorphic, and
there are at least two Python implementations written in C (CPython and
Stackless). So if you took all the C code which implements object-
oriented behaviour within CPython, added it to your C project, and then
used it directly as a framework, you would have polymorphic code written
using nothing but C.

Of course, this wouldn't be idiomatic C code, and you won't have syntax
for what you want, but that's why other languages get invented in the
first place.
 
M

Mark Janssen

Read and listen more. Write and say less.


Mark Janssen has no interest in learning. From a thread long-ago:

Mark said:
Ethan said:
Mark Janssen wrote:


Really?

--> int="five"
--> [int(i) for i in ["1","2","3"]]

TypeError: str is not callable

Now how are you going to get the original int type back?

Thank you for bringing this back up. Was it you who suggested that
built-in are re-assignable? Because this is a bad idea for the
reasons I just showed. My error in that example was going into arcane
points that I should have cross-checked in the Python language
definition (that built-ins were or were *not* assignable), then I
wouldn't have had to have made my (otherwise valid) point, that there
is no magical "stack" which will remember your language re-assignment
so that you can get it back, but then the example should have never
been pushed into existence in the first place.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,099
Messages
2,570,626
Members
47,237
Latest member
David123

Latest Threads

Top