Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The languages might permit it, but neither community condones the practice. Monkeypatching isn't condoned in either language, but you hear about it more often in Ruby because the form of open class it uses makes it very, very easy to monkeypatch a class and because of this, <a href="http://avdi.org/devblog/2008/02/23/why-monkeypatching-is-destroying-ruby/" rel="nofollow noreferrer">it's more acceptable in the Ruby community, but still frowned upon</a>. Monkeypatching simply isn't as prevalent or as easy in Python, which is why you won't hear the same arguments against it in that community. Python does nothing that Ruby doesn't do to prevent the practice.</p> <p>The reason you hear/read about it more often in Ruby is that this in Ruby:</p> <pre class="lang-ruby prettyprint-override"><code>class MyClass def foo puts "foo" end end </code></pre> <pre class="lang-ruby prettyprint-override"><code>class MyClass def bar puts "bar" end end </code></pre> <p>will give you a class that contains two methods, <code>foo</code> and <code>bar</code>, whereas this in Python:</p> <pre class="lang-python prettyprint-override"><code>class MyClass: def foo(self): print "foo" </code></pre> <pre class="lang-python prettyprint-override"><code>class MyClass: def bar(self): print "bar" </code></pre> <p>will leave you with a class that only contains the method <code>bar</code>, as redefinition of a class clobbers the previous definition completely. To monkeypatch in Python, you actually have to write this:</p> <pre class="lang-python prettyprint-override"><code>class MyClass: def foo(self): print "foo" </code></pre> <pre class="lang-python prettyprint-override"><code>def bar(self): print "bar" MyClass.bar = bar </code></pre> <p>which is harder than the Ruby version. That alone makes Ruby code much easier to monkeypatch than Python code.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload