What's better about Ruby than Python?

Alexander Schmolck a.schmolck at gmx.net
Wed Aug 20 13:38:39 EDT 2003


mertz at gnosis.cx (David Mertz) writes:

> Alexander Schmolck <a.schmolck at gmx.net> wrote previously:
> |Anyway, I still don't see a compelling reason why class statements
> |couldn't/shouldn't be mutating, rather than rebinding. Is there one?
> 
> I don't think there is any reason why the statement 'class' COULD NOT do
> what you describe.  But doing so seems much less Pythonic to me.
> 
> In Python, there are a bunch of statements or patterns that ALWAYS and
> ONLY binds names.  Having something that sometimes binds names, and
> other times mutates objects... and you cannot tell the difference
> without finding something that may be far away in the code.... well,
> that's not how Pythonistas like to think about code.

I agree this argument has merrit but I'm not sure I find it completely
compelling.

What's worse, looking at the top of a file and thinking "Ah so that's what
class Foo does" and

a) overlooking that somewhere below a 2nd class Foo gets created (and one
   assumes both with instances that insidously claim to be 'Foos').
b) overlooking that somewhere below a 2nd class Foo gets mutated (and thus all
   prexisting instances of it)

?

I think we'd agree that both options are generally undesirable (so one could
conceivably even make class statments with the same name in module scope raise
an exception and have the user jump through some hoops if he *really* wants
something along those lines, like having to define Foo #2 in a function and
have it returned). 

But at least for b) I can think of one use-case I find rather compelling,
namely interactive development. I'd also think that the nasty surprise in a)
might well be worse than in b), because at least all instances that claim to
be Foos will behave the same.

As I said, I'm not hung up on this since admittedly b) isn't necessary for
convinient interactive development, which is what I'm really keen on. It just
means that one could paste/send code directly to the shell to achieve the
desired effect, but as long as there is *one general way* to mutate classes,
the IDE/editor etc. could just be made to do the extra work of silently
inserting the required python code for class mutation before sending to the
shell.


'as





More information about the Python-list mailing list