From: Bill Kelly Date: 2011-10-07T04:39:06+09:00 Subject: [ruby-core:39997] Re: problems with Refinements Steve Klabnik wrote: > > Refinements for Rubyists: > Pros: > - protect a library from interference from other library's monkeypatches > Cons: > - End up making libraries harder to understand, since the details of > MyLibrary's String are opaque from outside MyLibrary > - Are a pretty complex feature to use. > - This complexity makes code with refinements hard to reason about. > > Refinements for Ruby Implementors: > Pros: > - Giving users a feature they want > Cons: > - Complex features are complex to implement > - Refinements in particular place a large burden on send (I > think), which is what makes the performance penalty so large. > - This feature affects Ruby at a very, very deep level, and > therefore deserves significant consideration While I don't disagree with the "Pros" you've listed, I've tended to view the benefits from a slightly different perspective: Refinements for Rubyists: Pros: - Protect *my* code from from another library's monkeypatches (given that some libraries use monkeypatching to facilitate their own internal implementations) Refinements for Ruby Implementors: Pros: - Allow me to use monkeypatching to add features that facilitate the internal implementation of my library without polluting the global method space. However, on the issue of the performance impact: There are some classes of applications I develop where Ruby's slow execution speed is already a daily source of concern. I would not like to see Ruby become significantly slower. Regards, Bill