Drew Mills wrote:
> Let me preface this post by saying that I'm no Ruby expert.  I like it.
>  It's fun.  But I won't claim extensive knowledge on it.
>
> So when this guy blogs about a Python quality that he feel is better
> than a Ruby quality:
>
>     It's the second generation that's going to be less enthused,
>     that's going to stare in bafflement at these classes that
>     mysteriously spawn methods, and trying to figure out what's
>     going when there's an exception in dynamically generated
>     code. You can monkeypatch code in Python pretty easily, but we
>     look down on it enough that we call it "monkeypatching". In
>     Ruby they call it "opening a class" and think it's a cool
>     feature. I will assert: we are right, they are wrong.
>
>     -- http://blog.ianbicking.org/theres-so-much-more-than-rails.html
>
> I am curious what this means.  Is Python against dynamic stuff?  And
> Ruby for it?  And so we just agree to disagree?  Or do I misunderstand?

There's some inaccurate ideas of Python in this thread, so I just
thought I'd chime in with a followup.  You can open a class in Python
just fine (except for some select built-in classes which are closed
except in subclasses, like int, list, dict).  Opening a class in Python
does not look as nice as in Ruby, and is used less often.  In Python it
looks like this:

  class Foo(object):
      pass

  def new_method(self, blah): ...
  Foo.new_method = new_method

You can also open instances in Python, replace objects with a delegate
or completely different implementation, and lots of other things, many
of which are very bad ideas.  There was also some mention of
method_missing in the thread, and I can assure you that it is present
in Python as well (__getattr__) and used fairly often.

My criticism isn't about what you *can* do in either language -- both
languages are quite open in this respect.  Instead it is about what the
community and the language itself encourage you to do (in this case
Ruby encourages opening classes by making the syntax appealing, and the
community encourages it because examples of opening a class are fairly
common).  In Python I consider opening a class to be a kind of code
smell  (http://xp.c2.com/CodeSmell.html) -- but smelly code happens,
and the entire point of code smell is that a technique might *suggest*
problems in code, but does not *necessarily* mean that the code is bad.
 The code might just be tackling a complex problem, or working around
problems in other code.

In a dynamic language like Ruby or Python we have to be very aware of
code smells because that's a big part of what keeps us sane.  In both
languages there are techniques that look fine, but experience shows us
are dangerous or indicative of misdesign.  Here I'm highlighting a case
where opinions on design differ between the communities.  It's easy to
tell they differ *because* the technique is available in both
languages.

Also, to generalize, it seems that the Ruby community is perhaps less
sensitive to code smells or more tollerant of magic compared to the
Python community, which I guess was my larger point.  Though I also
think that the specific case of opening a class is important enough
that it's also worthy of discussion, but this thread doesn't seem to
have much discussion of that particular issue.  If you have a sharp
tool it is good to discuss what the appropriate use of that tool is --
sharp tools are only safer than dull tools if you use them correctly!

  Ian