python and poor object oriented programming
Geek
In post-java I stated Python is not pure enough
. Daryl Tester asked, quite rightly, what the hell I meant by that. The explanation turned into a good enough rant that I decided to post it on the front page, so here it is.
While I find Python is good for procedural scripting work, I also get the feeling that its object-oriented capabilities have been largely tacked on as an afterthought, just like using modules as objects in Perl, or packages as objects in Ada.
Specifically, having to pass in a reference to the context instance object as the first argument for constructors and methods methods sucks. Badly. If you're not familiar with Python, here is an example class with one member variable, constructor and method:
class Foo:
frob = 0
foo = 0
def __init__(self, foo):
self.foo = foo
def frobMore(self):
self.frob = self.frob + 1
Note that both the constructor and method has self as the first parameter. That is how the reference to the current instance object is obtained. You must add it in for every constructor and method in the class. I find this to be quite poor. Surely it could have been arranged so that self is automatically in scope when invoking those constructs. The complier knows you are defining a class, it should just make it happen! The whole point of high-level programming languages is to make a programmer's life easier, especially when it comes to scripting languages. Especially in a language that prides itself on its brevity.
This issue gets worse, however. To construct an instance of the class above and invoke frobMore I would do this:
somefoo = Foo(99)
somefoo.frobMore()
The interesting thing here is that when constructing an instance or invoking a method, you do not supply the self parameter as a parameter. It is passed in for you. This inconsistency really annoys me. It is very, very poor.
There are probably a few other minor nits, it seems to be impossible to dynamically modify the class at runtime, for example.
Overall I think Ruby or even Javascript (think Mozilla's hardcore Javascript 1.5 implementations here, not JScript or other such tripe) to be much better scripting languages for object oriented programming. They feel like real OO languages when you are cutting code, which is quite important to me.
Comments
Add a Comment