From: Lennon Day-Reynolds Date: 2003-03-21T17:54:00+09:00 Subject: Re: Strong advantages over Python Paul Prescod wrote: > I'm not going to go back and forth on preferences, but just talk about > technical details. > > Lennon Day-Reynolds wrote: > >> ... >> Python class definitions always seemed much more to be a sort of >> template for object creation, esp. with the required 'self' parameter >> and lack of runtime association b/t method definitions and object >> method bindings. > > > I'm not sure what you mean by this latter bit. The self paramater is > purely a syntactic issue. And object method bindings do have a > "runtime association" with method definitions. That's how the > interpreter finds which methods go with which object. The specific difference I was trying to illustrate was the ability to, in Ruby, add a method to an existing class, and have that change then cascade through to each instance of the class. To use a trivial example, if I were to add an 'average' method to the array method like so... class Array def average sum = 0.0 self.each {|i| sum += i} sum / self.size end end ...any existing instances of Array would then have this method available. In Python, however, I would have to re-define/load the class, then re-instantiate any objects of that type in order to access the new instance method. This could be seen as a benefit for some Python code, as the same behavior allows you to assign new functional values to instance methods of objects. However, the convencience of the "Ruby way" (esp. w.r.t extension of built-in or library classes) overweighs the disadvantages for me, at least. >> ... (And yes, before anyone mentions it, I've seen the recently-added >> functionality in Python 2.2 to create that kind of protected >> attribute. IIRC, however, it requires defining a new class that >> "impersonates" a simple scalar, and it will be quite a while before >> the existing body of Python libraries and applications are updated to >> use it.) > > > There is no need to impersonate a scalar. > > http://www.python.org/doc/2.2.1/whatsnew/sect-rellinks.html#SECTION000340000000000000000 This actually isn't what I was thinking of at all -- the 'property' type still requires hand-writing the get/set/del methods, and what I was remembering (quite possibly incorrectly) was a type which could override the assignment and value operatations to allow more complex logic to be implemented. I'm really not trying to impugn the usability, power, or quality of the Python language and libraries at all. My whole point was just to illustrate the things that I use on a semi-regular basis that are significantly easier to do in Ruby, if not impossible in Python. Just as many people find that Java, C++, VB, etc. are more than sufficiently expressive, concise, and powerful for the kind of programming they do on a regular basis, Python is more than enough for many people (and for a time, didn't really constrain me at all). Now, I just find that Ruby not only "fits my brain" better than Python does, it supports certain kinds of dynamicism, abstraction, and syntactic sugar that make me more productive. > > Paul Prescod Lennon Day-Reynolds