Ruby 2.0 Implementation Work Begins: What is Ruby 2.0 and What’s New?
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.
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:
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.
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" 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).
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
- 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
- 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.