Ruby 2.0 Implementation Work Begins: What is Ruby 2.0 and What’s New?
Yesterday, Matz made a commit to the MRI Ruby repository bumping the trunk version from 1.9.4 to 2.0.0, marking the start of the work of implementing the long-discussed ideas for Ruby 2.0.
What is Ruby 2.0?
Ruby 2.0 is the next major version release of MRI Ruby, the de facto official Ruby implementation.
Ruby 1.9.3 is due out any time soon and Ruby 1.9.4 is under active development (it has moved to a separate branch now that trunk is 2.0.0). We recently learned that Ruby 2.0 would then follow Ruby 1.9.4.
Will Ruby 2.0 be a huge leap forward?
No. While 2.0 will include a number of syntax changes, new features and general improvements, mentioned below, it is anticipated to remain backward compatible with code written for 1.9.3 and Matz has stated that the changes are less significant than those made in the 1.8 to 1.9 jump.
The version number goes up to 2.0 but the changes are rather small. Smaller than the ones we made in 1.9.
Matz
The discussion surrounding Ruby 2.0's feature set spans back several years (mostly on the ruby-talk and ruby-core mailing lists) and 2.0 was initially expected to introduce significant syntax changes and not be backwards compatible. Things have changed with Ruby 1.9 moving into production (it was originally a development only version) and 2.0 being an evolution rather than a revolution.
What will (probably) be new in Ruby 2.0?
Ruby 2.0 is still not well defined. At the moment, ideas and features are being actively suggested and discussed, but a number have been tipped to make it into Ruby 2.0 at this early stage:
Keyword Arguments
In Ruby 2.0: What We Want to Accomplish in the Near Future (recorded in 2010), Matz showed off an example where 1.step(20, 2)
could become 1.step(by: 2, to: 20)
with the method definition of def step(by: step, to: limit)
.
An implementation of keyword arguments by Yusuke Endoh actually triggered the discussion to move trunk to 2.0.0 so this is actively being discussed and implemented.
Bytecode export/import
Ruby 1.9 runs on the YARV virtual machine and so will Ruby 2.0, but Ruby 2.0 is expected to make it simple to save pre-compiled Ruby scripts to bytecode representations and to then run these directly. Running pre-compiled bytecode will skip the parsing stage of the standard interpretation process. If you use Rubinius or JRuby you may be familiar with this concept.
Refinements
"Refinements" are a construction to make monkey patching safer. Essentially you could "refine" a global class within the context of a specific module so that the monkey patches would only apply in a certain context. Yehuda Katz wrote an excellent writeup about refinements last year.
Refinements are.. controversial. The performance hit they'd introduce has recently made them less likely to arrive in Ruby 2.0 but I don't believe they're entirely off the table yet. Some form of namespacing of class modifications will probably eventually make it in, however. Another implementation has been called 'traits' and is shown off in the Matz video (linked above).
Standard libraries becoming gems
On Twitter today, Aaron 'tenderlove' Patterson of the Ruby core team said that the Ruby standard library would be 'moved to gems' in Ruby 2.0 although many of these would still be included with the implementation (rather than being an optional extra download).
And more..
As I said before, things are a bit up in the air, but the ideas surrounding Ruby 2.0 should begin to settle over the next year.
A couple of weeks ago, Koichi Sasada posted the results of a Ruby 2.0 feature questionnaire to the ruby-core mailing list and encouraged people to extend it. It's not a list of features that will make it into Ruby 2.0, but an attempt to see what people would like.
Koichi's initial list was:
- Cleanup syntax
- Bytecode export
- Symbol GC
- Remove Proc binding
- Macros
- Getting parse tree
- Getting source code
- Cross thread Fiber migration
- Standard Gem
- Review all standard libraries
- Remove obsolete one standard libraries
- Improve Proc#curry
- Non-blocking I/O
- Dtrace
- GC API (replaceable GC)
As Ruby 2.0 development continues, I'm going to regularly summarize what's going on and show off new features here on Ruby Inside, so keep your eyes peeled :-)
[ad]Gauges is a real time traffic analytics system so you can analyze all your traffic in seconds. Collect and analyze your web traffic for all your sites in real-time using their fast, reliable, hosted system and see overview data for all your sites on a single page. Click here to learn more.
October 20, 2011 at 5:35 pm
It's step(limit, step), isn't it? Thus 1.step(20, 2), not 1.step(2, 20).
Your syntax feels so much more natural though
October 20, 2011 at 6:42 pm
Great!
I love ruby 1.8 and 1.9. Backward compatibility is very good and won't diminish the momentum Ruby has gained. Good little things add up too.
October 20, 2011 at 6:59 pm
I miss multiple inheritance.
October 20, 2011 at 9:13 pm
Is there any word on performance improvements wrt the YARV virtual machine? Improvements in its garbage collection? etc.?
October 20, 2011 at 10:44 pm
@ano: You're right. I've fixed it :-) Thanks!
October 24, 2011 at 6:53 pm
Is module prepending (which would remove the need to ever do alias_method_chain) still a possibility?
October 27, 2011 at 1:55 pm
*Yawn*
They should make Rubinius the default VM for 2.0.
I'm so fed up with YARV segfaulting all the time, I guess I'm going to move to Perl or Python.
October 27, 2011 at 3:09 pm
@Alexey, Good one. I laughed.
October 29, 2011 at 12:43 am
I don't feel like Ruby needs many more features; I'd rather see more focus on performance improvements.
Pingback: Ruby 2.0: Planos do criador | SWX Softwares - Desenvolvimento e Design Web
Pingback: The Ruby Standard Library To Be Converted to Gems for Ruby 2.0?