What's better about Ruby than Python?
Alex Martelli
aleaxit at yahoo.com
Mon Aug 18 11:55:27 EDT 2003
Alexander Schmolck wrote:
...
> I recall the following, roughly in order of importance (treat with
> caution, it's some time that I looked at Ruby):
>
> 0. I it's possible to redefine classes at runtime without going bonkers
> (instances automatically get updated to the new class definitions).
This is generally feasible in Python, too -- but not with built-in types
(e.g., you can't redefine what "+" means on integers, while in Ruby you
could).
> This, I think is by far python's greatest flaw, amongst other things it
> greatly compromises its interactiveness, which is a key virtue. If
> someone can explain to me how I'm wrong on this and python's behavior
> really is sane, I'll be eternally grateful.
I don't think I understand what you're saying. For example:
>>> class X:
... def amethod(self): return 'just a method'
...
>>> x=X()
>>> x.amethod()
'just a method'
>>> def abettermethod(self): return 'ah, now THIS is better!'
...
>>> X.amethod = abettermethod
>>> x.amethod()
'ah, now THIS is better!'
>>>
Isn't this "redefining classes at runtime // instances automatically
get updated", too? If you want to redefine a bunch of entries in X,
rather than just a few, X.__dict__.update(someotherdict) -- or even,
shudder, reassigning X.__dict__ altogether... -- may perhaps be
preferable, but I personally like the explicitness of assignments
for most cases of such (rare) tasks.
Alex
More information about the Python-list
mailing list