Be Prepared for Ruby 1.9.3 and 1.9.4: What’s New and What’s Different
On August 1, 2011, Ruby 1.9.3 preview 1 was released. The final version isn't yet out (as of September 23) but Ruby 1.9.3 is going to be the next, full production-level release of MRI Ruby. But what's the deal with 1.9.3 (and its successors, Ruby 1.9.4 and 2.0)? Keep reading!
The Summary
Ruby 1.9.3 is a relatively minor improvement on the Ruby 1.9.2 we already know and love. In short:
- a focus has been placed on performance with file loading, File and Pathname all significantly improved
- Ruby 1.9.2 mostly fixed down the language specification for 1.9; 1.9.3 is mostly work on a 'better implementation'
- you can tune the garbage collector via environment variables (more on this in a post coming soon!)
- Ruby's license changes from dual Ruby + GPLv2 to dual Ruby + 2-clause BSD
- improved GC performance with a lazy garbage collector
- a 'better strategy' for the GIL / GVL
- test/unit supports parallel testing
- Random.rand tweaks (and rand() now accepts ranges)
- io/console, a new library in the stdlib
- 4 new encodings (so far) - cp950, cp951, UTF-16, and UTF-32
- extra String methods
- a number of tweaks to formatting strings
- Module#private_constant and Module#public_constant
- a smattering of other bits and pieces, but this is the TLDR overview!
For some examples of the above, however, read on.
Yuki 'yugui' Sonoda on Ruby 1.9.3
At RubyConf Taiwan (held August 26-27, 2011), core team member Yuki 'yugui' Sonoda gave a talk called Ruby 1.9.3 and Ruby 1.9 Development which outlined her current thinking on Ruby 1.9.3, Ruby 1.9.4, and Ruby 2.0. It's not very long and worth a watch.
You can watch the video on Vimeo or see the slides on SlideShare. Alternatively, you may see the video embedded above.
Yugui's talk was only short but the key points were that:
- Ruby 1.9.2 essentially fixed down the language design for 1.9; 1.9.3 is just a 'better implementation'
- Ruby 1.8 has "no future" (she stated this a few times) but it will be "supported" for a few years to come
- there is no intention to release a Ruby 1.8.8
- "You need to switch to Ruby 1.9"
- Ruby 1.9.3 will be out very soon
- the license was changed to joint BSD because the release of GPLv3 forced a rethink on licensing
- the locking strategy related to the GIL / GVL has been improved, resulting in improved performance
- test/unit's parallelization features are well suited for testing Ruby's stdlibs more quickly
- you can "safely switch to Ruby 1.9.3 from Ruby 1.9.2" as there are "few incompatibilities"
- the new "lazy GC" will improve the response time of the garbage collector and decrease overall GC throughput - more info in this article, for the curious
- Yugui is not particularly familiar with RubySpec - it seems to continue to not be a focus for core MRI implementers
A Selection of 1.9.3 Changes
I've cherry picked a few changes in 1.9.3 to highlight.
Faster loading - the load.c patch
Recently, I wrote all about the load.c file loading performance saga in Ruby 1.9.2. These issues have begun to be addressed and a nifty patch has enabled Ruby 1.9.3 to post significantly improved loading times for apps with large trees of files to load. You could see anywhere from a 5% to 40% reduction in load times for your apps.
Time#strftime supports %:z and %::z
Time.now.strftime("%:z %::z") # => "+01:00 +01:00:00"
Time#strftime
now supports some extended formats for timezones. :z
includes the minutes and ::z
gives the full HH:MM::SS.
String#prepend and String#byteslice
Among some changes to the String class are a couple of new methods. First, prepend
:
a = 'world'; a.prepend('hello '); a # => "hello world"
String#prepend
prepends one string to another, in-place. The result is equivalent to using a[0,0]
, in this case.
Next, byteslice
will let you get access to sections of a string at the byte (rather than character) level:
a = 'hello'; a.byteslice(2, 2) # => "ll"
New character encodings
CP950, CP951, UTF-16, and UTF-32 encodings have been added. Previously, UTF-16 and UTF-32 were available in big-endian (BE) and little-endian specific forms. For example: Encoding.find("UTF-16LE")
. I have not yet confirmed if the new UTF-16 and UTF-32 encodings support the byte ordering marks that they should, but am currently assuming so. CP950 and CP951 are Microsoft encodings for Chinese character sets.
Changes to 'Random'
The Random class now accepts ranges on its rand
class method. In 1.9.2, this was only allowed on its instance method. For example:
Random.rand(5..9) # => [a number between 5 and 9]
A side effect of this is that Kernel.rand
now also supports ranges in 1.9.3. For example:
rand(5..9) # => [a number between 5 and 9]
#__id__ moved from Object to BasicObject
BasicObject is the new grand-daddy of the inheritance tree in Ruby 1.9 and in 1.9.3 it gains access to the functionality of the object_id
method by way of __id__
which has been moved into BasicObject from Object. This may help those of you using BasicObject for delegators, proxies, and the like.
BasicObject.new.__id__ # => 2152881920
More?
If you want to pick up on more changes, see the Ruby 1.9.3 NEWS document or, perhaps, check out my Ruby 1.9 Walkthrough screencast ($16) which has an entire section dedicated to things that are new in Ruby 1.9.3.
The Future: Ruby 1.9.4
In her talk, Yugui mentioned two extra production releases of Ruby to come after Ruby 1.9.3. The first was unnamed and was said to be a 1.9 release with minor language changes to 1.9.2/3. In the Q&A, someone asked Yugui if this would be called Ruby 1.9.4 but she said it was still under discussion but hoped it would be called 1.9.4. This unnamed next release would, however, have complete backwards compatibility for code written in Ruby 1.9.2/3.
The Future: Ruby 2.0!
The second release after 1.9.3 "should be called Ruby 2.0", however. It will have significant changes but Yugui notes that "it should be comfortable with 1.9.3" and that you should be able to "safely switch" to 2.0, indicating that any significant changes wouldn't involve removing core language elements or permanently changing core syntax features.
It has previously been said, however, that Ruby 2.0 could be "several years" away, so don't get too excited about this yet. Now is the time to start weighing if you want to influence Ruby 2.0's design, however!
Still getting to grips with Ruby 1.9? Try my walkthrough
I recently released a screencast called Ruby 1.9 Walkthrough, a mega walkthrough of what's new in Ruby 1.9.2 (and Ruby 1.9.3) from the perspective of Ruby 1.8.7. If you're still primarily a Ruby 1.8 based developer and aren't entirely sure about what's new in Ruby 1.9, check it out.
September 23, 2011 at 5:44 pm
More info on the GIL change:
http://groups.google.com/group/ruby-talk-google/msg/d5cc8c681643ecd6
September 27, 2011 at 7:45 pm
Shouldn't String#prepend be called String#prepend! since it changes the string in place?
September 27, 2011 at 8:20 pm
That's been a common question (direct to me, at least). The answer, however, is no. Despite the common understanding, bang methods in Ruby (at least in the core and stdlib) are used as 'dangerous' versions of already existing methods. If the method is the only one, it's non-bang whether it works in-place or not. Array#keep_if is another example.
September 28, 2011 at 5:21 pm
Ah ok, thanks. That makes sense. At least they're being consistent with how they've done it in the past.
September 29, 2011 at 12:19 am
Is the next non 1.9.x release called 2.0 only because 1.10 would cause confusion?
September 29, 2011 at 8:21 am
Is there any keyword like the final keyword in java..to fix a variable with a value so that it is never altered.
September 29, 2011 at 6:02 pm
Here's another post which takes a casual look at some of the upcoming 1.9.3 changes only:
http://www.mutuallyhuman.com/blog/2011/09/28/a-casual-look-at-upcoming-changes-in-ruby-1-9-3
September 29, 2011 at 8:04 pm
I watched Matz's talk on Ruby 2.0, it was very interesting. You should link it in the post. http://www.youtube.com/watch?v=t9LMOydfc4k
September 29, 2011 at 9:35 pm
@Andrew Grimm
While I dislike ".10" version numbers, I agree with you that they shouldn't call a (semi)minor change "2.0" just because they ran out of space and don't like .10.
September 30, 2011 at 6:52 am
I doubt that the Ruby core team are worried about staying on the 1.9.x track even if there are bigger changes to be made. "2.0" has been said to be backwards compatible with 1.9.3 anyway and 1.9.2 was a real leap over 1.9.1 (which in turn was a leap over 1.9.0). If you consider how different 1.8.7 was to 1.8.6, I think we'd see 1.9.5, 1.9.6, and so on, if 2.0 wasn't warranted.
And IMHO it's not about liking/disliking .10, but .10 is a nonsensical travesty that makes as much sense as using imaginary numbers in versions. Just because a few versioning systems have allowed it in the past (looking at you, Perl) doesn't mean it's ever a good idea ;-)
September 30, 2011 at 10:41 am
Thanks for this summary!
Readers might also find my article about ruby 1.9 changes interesting:
Ruby 1.9 changes, cherry picked
October 9, 2011 at 4:41 pm
How secure RoR is, as considered it in web oriented concerns...?
October 9, 2011 at 4:47 pm
I think Ruby has an exponential growth since 2006, So what you think about its future? What about its impact in India?
October 16, 2011 at 4:12 pm
"And IMHO it's not about liking/disliking .10, but .10 is a nonsensical travesty that makes as much sense as using imaginary numbers in versions. "
it's much better to have 1.10 than have 2.0 if the change from 1.9 is only minor.
October 16, 2011 at 5:37 pm
I disagree, but in theory we have 1.9.4, 1.9.5, and all the way through to 1.9.9 before it would become a concern. Seems they are keen to skip to the 2.0 though :-)
Pingback: RubyConf Taiwan 2011 籌辦心得 | ihower { blogging }
November 3, 2011 at 5:05 pm
What's wrong with, say, 1.10.0? How is it "nonsensical" or a "travesty"? They are not decimal points.
November 27, 2011 at 5:49 am
You could eyeball Java as well (Java 2 vs Java 1.2 etc)
call it 1.10 then there is no relation however slight with Java mentality and stays more like a linux kernel.
Pingback: Ruby News and Releases in 2011: A Retrospective