Hacker News new | past | comments | ask | show | jobs | submit login
"I decided not to introduce full refinement for Ruby 2.0." (ruby-lang.org)
73 points by steveklabnik on Nov 29, 2012 | hide | past | favorite | 20 comments



Repost of the message, since bugs.ruby-lang.org appears to be down:

    Issue #4085 has been updated by matz (Yukihiro Matsumoto).
    
    
    Since there still remain undefined corner case behavior in refinements, 
    and the time is running out, I decided not to introduce full refinement 
    for Ruby 2.0. The limited Ruby 2.0 refinement spec will be:
    
    * refinements are file scope
    * only top-level "using" is available
    * no module scope refinement
    * no refinement inheritance
    * module_eval do not introduce refinement (even for string args)
    
    In addition, Module#include should add refinements to included modules, 
    e.g.
    
      module R1
        refine String do
          def bar
            p :bar
          end
        end
      end
    
      module R2
        include R1
        refine String do
          def foo
            p :foo
          end
        end
      end
    
      using R2
      "".foo
      "".bar
    
      module R1
        refine String do
          def bar; p :bar end
        end
      end
    
      module R2
        include R1
        refine String do
          def foo; p :foo end
        end
      end
    
      using R2
      "".foo
      "".bar  # does not work now
    
    You can treat top-level "using" as soft-keyword, as long as it does not 
    change the behavior (but performance).
    
    Matz.


I love Ruby with all my heart but that seems to be quite a mess. While a not-well-thought-through feature in some application can be forgiven (and maybe even removed), in language design it cetainly has no place. And while this should be a secondary consideration, I really feel for those poor JRuby and Rubinus guys. As if Ruby wasnt "dynamic" enough, the sheer complexity of implementing refinements must be awful!

I think, they should just leave it out (at least for now) and rather spend some more time on performance, stabilty and memory usage in MRI...


Agreed. Ruby is already difficult to debug on projects of any significant size, and frequeny docficut to wrap your head around where various behaviors are originating from. Ruby's dynamism is -- or was -- a strength, but it feels like the language maintainers might have taken it a bit too far.


It's rather easy to figure out where something is originating in the REPL particularly if you use pry.


I think there is too much pressure because of the version number. If it were 1.10 the eyes wouldn't be on it as much and they could be more incremental without anyone complaining.


This, I feel, is a rather striking difference between the development processes in ruby and python and tells more about them than any superficial language benchmark or example could.

This is how generally new things to python are introduced: http://www.python.org/dev/peps/


Ok, tell me if I have this correct:

  module Foo
    def hello
      puts "Hello World"
    end
  end

  ...in a different file...

  foo = Foo.new.msg
Q: What does that print? A: There is no way to tell. It depends on what the 'using' line (not shown) is, and whether anything has refined 'Foo'.

Seems like bad action at a distance, to me. Or am I missing something? The example about the effects of refining 'each' is also pretty disconcerting.


Seems like a NoMethodError to me.


NoMethodError: undefined method `new' for Foo:Module

You can't initialize modules, I think you meant to make Foo a class.


Steve, I agree with you that this is a lot of change for something in preview, but didn't Rails 3 have some last minute changes before its release as well, and 3.1 was a big jump also?

Matz, Shugo, and Charlie will figure it out soon enough, but it is interesting. What is more upsetting to me really is the version number. 2.0 implies some major changes, but 1.9 was more major. It should be 1.10, and then they should work on something more revolutionary for 2.

There is a lot of pressure on Matz also. They really need to spend more time on it.


> didn't Rails 3 have some last minute changes before its release as well, and 3.1 was a big jump also?

I'm not sure about 'last minute,' but yes, 3.1 was a big jump. Rails doesn't follow SemVer, neither does Ruby.

> They really need to spend more time on it.

This is absolutely true, and is my biggest complaint.


Anyone have an explanation on this part at the end?

      using R2
      "".foo
      "".bar  # does not work now
I can't figure out why "".foo would work in this case but "".bar wouldn't.


edit: Disregard this, it's actually the opposite (viz. next comment) and the inheritance remark is probably only for straight class inheritance.

> no refinement inheritance

R2 included R1, which defined `bar` on String. Only the methods defined on R2 are used now with this change of plans. (I couldn't get to the ruby-lang issue, but I assume that's the reason).


...except the previous listing does basically the same thing, but doesn't have any comment about R1's refinements not working when you're using R2.


Ah, I misread the feature list (namely the text right above the examples, about Module#include).

Matsumoto gives two of the same examples, the first in how he wants the feature to work (R2 having the refinements of R1 if it includes it) and the second in how it works at the moment (or doesn't work).

If you try that code it breaks, he wants it to not break and return :bar.


Thank goodness I wasn't the only one confused by this. I stared at the code listing and stared at it, only to wonder what the difference was. :)


I wonder if the problem refinements are trying to solve has already been tackled in the 40+ years of computer programming.

If so, is there something to just learn from or copy for the Ruby team?


Huh, refinement is most of the reason I would want to upgrade to Ruby 2.0. 1.9 works for well for what I want to do.


I think this link is broken or overloaded.


Redmine appears to be quite slow at the moment.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: