[Tutor] What's pure OO? [was Re: Why do I not get an error when I mistakenly type ...]

2016-01-25 Thread Steven D'Aprano
On Sat, Jan 23, 2016 at 08:30:48PM +1100, Cameron Simpson wrote:

> That is the pure OO way; 

Is this the room for an argument? I'd like the full half hour please.

http://www.montypython.net/scripts/argument.php


Without wishing to single out Cameron specifically, I'd like to take 
exception to the way folks are tossing around the term "pure OO". I 
don't think that's a term that adds much light to the discussion, and I 
think it risks being understood as "real OO", a term which is downright 
harmful.

At the very least, people ought to define their terms. What on earth is 
"pure OO"?

If I were to guess, I would think of pure OO in one of two ways:

(1) All values in the language are objects.

That describes Python: everything in Python, modules, ints, strings, 
functions, even classes themselves, are objects. That makes Python as 
"pure" an object-oriented language as it is possible to get.

In comparison, Java fails miserably: unlike Python, but default Java 
treats numbers, strings, booleans as native "unboxed" values, not 
objects.

This is the definition of "pure OO" language given by Wikipedia:

https://en.wikipedia.org/wiki/Object-oriented_programming#OOP_languages


(2) Alternatively, "pure OO" might mean a language which uses only OO 
syntax: alist.len() not len(alist).

Obviously Python is not pure in that sense, but then (i) I don't know 
any language which is, most languages allow non-OO syntax at least for 
arithmetic; and (ii) syntax is the most superficial and unimportant part 
of Object Oriented Programming. 


(3) Others (but not I) might fall for the "No True Scotsman" fallacy and 
use "pure OO" to mean "proper OO", for whatever definition of "proper" 
they like. Unfortunately, or perhaps fortunately, OO covers a lot of 
ground, and very little is mandatory. Just as true Scotsmen do sometimes 
wear trousers, and eat porridge with honey and milk, so almost any 
feature of OOP is optional:

(a) Classes are optional; prototype-based languages like Javascript 
and Lua are no less OO than class-based languages.

(b) Subtyping and inheritence are optional. Some people like to 
reserve the term "object-based" for languages with objects but no 
inheritence. Others distinguish between languages with nominal 
subtyping, like C++ and Swift, and structural subtyping, like Ocaml and 
Go. (Python arguably has both, as duck-typing is a form of 
structural subtyping.)

I could go on, but suffice to say that I will strongly object (pun 
intended) to any suggestion that Python is not a "proper" or even "pure" 
OO language because it lacks certain features some other OOP languages 
provide.

For example, it's popular in certain circles to say that No True OO 
Language lacks information-hiding (sometimes wrongly called 
encapsulation). Since Python has no "private" keyword, Python cannot be 
a proper OOP language like Java, or so they say.

But Java's private variables are not that private:

http://tutorials.jenkov.com/java-reflection/private-fields-and-methods.html

and Python's cooperative information hiding ("just ignore anything 
starting with a single underscore, since that's private") is actually no 
less private than Java's.




-- 
Steve
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What's pure OO? [was Re: Why do I not get an error when I mistakenly type ...]

2016-01-25 Thread Alan Gauld
On 25/01/16 15:02, Steven D'Aprano wrote:
> On Sat, Jan 23, 2016 at 08:30:48PM +1100, Cameron Simpson wrote:
> 
>> That is the pure OO way; 
> 
> Is this the room for an argument? I'd like the full half hour please.

Personally I see OOP as a style thing rather than a language
issue. And I do think there is some sort of a "pure" definition
in all the object model theory papers that abound on the subject
in CS departments around the planet. (But that still leaves a
lot of wriggle room due to differences in opinion among the gurus)

But like most "pure" approaches it's thoroughly impractical in
isolation. As a result no pure OOP language exists because
it would be unusable. (Just like with pure FP, another case
where cries of purity are rife.)

OTOH striving towards purity is no bad thing. There is usually
a good reason lurking in the background. Otherwise we'd all
still be programming with goto and globals and variable names
like A$... But structured programming too has its
purists... remember single exit points anyone? (Actually F#
does insist on those!)

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor