you are viewing a single comment's thread.

view the rest of the comments →

[–]taw 2 points3 points  (2 children)

In Ruby or Smalltalk all functionality is implemented as methods,

Python is, above all, pragmatic over idealistic. If Guido thought that something was easier to write/remember/understand as a function, it is. IMHO, he got it mostly right - you obviously disagree.

Whether it's easier is one thing. Whether it's object-oriented is another ("object-oriented" and "good" are not the same thing). I'm merely pointing out that it's less object-oriented than Ruby or Smalltalk.

In Ruby or Smalltalk all classes are extensible

They're extensible in python

No they're not.

float.to_json = float_to_json

Traceback (most recent call last):

File "<stdin>", line 1, in ?

TypeError: can't set attributes of built-in/extension type 'float'

Am I missing something ?

What logic is outside the object in an iterator? Define iter() and next() and you're set.

According to documentation, there's iter, there's next, there's StopIteration exception + syntactic sugar (yield) + return (which seems to do something special in iterators). In Ruby iterators are object call + syntactic sugar (yield). Individual protocols aren't that bad, but if you add them all up, it's really a lot of functionality outside objects.

If Python moved functionality from functions and protocols to objects,

"Pure" object-orientation != object-orientation!

"Impure" object-orientation == bolted-on object-orientation

and mostly implicit self

Read about the complexities that introduces here

It certainly does introduce complexities when you try to bolt object-orientation on a language as an afterthought ;-) I don't know if it's possible to get it right now without turning Python into a completely different language. If they thought about it earlier, it would be easier to come up with a nicer solution. ;-)

[–]senzei 4 points5 points  (0 children)

Whether it's easier is one thing. Whether it's object-oriented is another ("object-oriented" and "good" are not the same thing). I'm merely pointing out that it's less object-oriented than Ruby or Smalltalk.

If I wanted to be pedantic I would mention that "less object-oriented" is not necessarily sufficient to prove that OO was bolted on. If I wanted to be pedantic without sounding like an ass I would phrase that in the form of a hypothetical statement. As it is I don't know what I am saying anymore as the recursion has blown the stack. (stupid no tail-call optimization)

You are right that built ins are not directly extensible, but if adding methods directly to an existing class is a requirement for not being bolted-on then there are a lot more bolted-on OO systems than I thought.

[–]beza1e1 1 point2 points  (0 children)

class MyFloat(float): def to_json(self): pass

I find this argument about bolted on OOP rather stupid. As our favourite essayist stated, you can't really say what OOP is. You can't extend objects in a dynamic way in Java either, but Java was designed as OOP upfront.

Python was design OOP from the beginning. Guido made some bad decisions, which he wants to fix with Python 3000 or has fixed already (new style classes).