[TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Fri Apr 19 12:37:59 EDT 2013
On Fri, 19 Apr 2013 09:07:15 -0400, Roy Smith wrote:
> Often, when you talk to C++ people, they will tell you that
> encapsulation is what OOP is all about. What they are doing is saying,
> C++ isa OOPL, and C++ has encapsulation, therefore OOPL implies
> encapsulation. When they look at something like Python, they say,
> "That's not object oriented because you don't have private data".
>
> I suppose people who grew up learning Python as their first language
> look at something like C++ and say, "That's not OOP because classes
> aren't objects", or something equally silly.
You might say that, but I find in my experience that Python users don't
tend to fall for the "No True Scotsman" fallacy anywhere near as often as
(say) Java or C++ users. I'm not sure what the reason for this is.
Perhaps it is that the Python community as a whole is more open to other
languages and paradigms, and less stuffed to the gills with code monkeys
who only know how to copy and paste code from StackOverflow. The Python
community frequently tosses around references to other languages,
compares how Python would do something to other languages, or relates how
certain features were borrowed from language X (e.g. list comprehensions
are taken from Haskell; map, filter and reduce are taken from Lisp). But
when I read forums and blogs about (say) Java, it's nearly always about
Java in isolation, and one would be forgiven for thinking it was the only
programming language in existence.
I don't think that there is One True Way to design an OOP language, but I
do think there are *degrees* of OOP. Java, for instance, I would say is
only moderately OOP, since classes aren't objects, and it supports
unboxed native types. I think the first part of that is a weakness, and
the second is a pragmatic decision that on balance probably is a
strength. Yes, Python's "everything is an object" is a cleaner design,
but Java's unboxed types leads to faster code.
It also depends on what you mean by OOP. If we judge Python by the fact
that everything is an object, then it is strongly OOP. But if we judge
Python by its syntax and idioms, it is only weakly OOP, even less than
Java.
--
Steven
More information about the Python-list
mailing list