Thoughts on Ruby 2.0 – Guest Blog By, David Lumley.

Late last month Ruby 2.0 was publicly released. The language has grown over the twenty years since it’s inception, and 2.0 marks an important milestone. 2.0 is more than just a version number; it adds numerous improvements to the language. The most interesting additions (for me) are refinementsModule.prepend and general performance improvements and how they shape Ruby as a language.

Refinements

Refinements have been an issue of contention as their implementation can seriously affect the performance gains runtimes like JRuby and Rubinius provide, and the readability of the code itself.

The ability to monkey patch and extend or replace core functionality is both a blessing and a burden. It makes modifying and inserting functionality exactly where you need to simple, but it’s also possible to pollute objects in unintended ways due to the global nature of monkey patching. Refinements aim to solve this by allowing local modifications to the call stack with a syntax similar to mixins. As a user you can create a refined module or class using refine and then implement this functionality within the target class/module through the using function.

Ben Hoskings makes a good case for why refinements can be confusing (along with a fantastic overview of other the other changes). I wouldn’t be surprised if the implementation changed as 2.0 moves forwards.

Module.prepend

Module.prepend offers functionality similar to ActiveSupport’s alias_method_chain without the need to include ActiveSupport. If you’re unfamiliar with alias_method_chain it’s another way of extending built in methods but rather than monkey patching them, it chains them.

For those who don’t use ActiveSupport (i.e. developers not using Rails) Module.prepend adds syntactic sugar that makes adding functionality in this way much easier.

General Performance

Just as 1.9 improved Ruby’s performance over 1.8 so 2.0 does over 1.9. Many of the changes are internal, making your applications faster without any manual changes. In particular, the speed with which an application can be loaded and garbage collection performance has improved significantly.

This has very real implications for people still using 1.8.7 Ruby Enterprise Edition because it’s memory handling abilities. While Ruby 1.9 improved a lot upon the memory management and performance of 1.8.7, Ruby 2.0 makes a clear case for upgrading.

Support and Upgrading.

At the time of writing, the current version of Ruby is 2.0-p0 meaning it is the initial 2.0 release. The accompanying release notes state 2.0 is a stable release so it’s fit for use in production. It’s certainly worth using it in development before hand to ensure all your tests are running and passing successfully.

If you’re still using 1.8.7 it’s time to migrate right now. 1.8.7 will be five years old soon and support is being dropped. Not only are the improvements in both 1.9 and 2.0 meaningful, developers (such as the Rails team) are abandoning support for versions before 1.9. I wouldn’t be surprised to find less people ensuring gem compatibility with 1.8.7 either. Migrating isn’t impossible, but there are a few caveatsin addition to any issues migrating from 1.9 to 2.0.

Migrating from 1.9 is considerably easier. While 2.0 is a brand new major version, many core changes (such as moving from MRI to YARV) happened in 1.9. The small amount of incompatibilities are noted near the bottom of the release notes.

Unsurprisingly, Matz presents a much more thorough overview of 2.0. It’s worth the watch, if only to understand how the Ruby contributors continue to make Ruby a language you’ll want to program in, rather than one you have to.

Follow David here; @davidlumley (this guy is one of the most talented and loyal web developers I have ever had the pleasure of hiring)! PS. He’s not for hire.

Advertisements

...Go on say something;

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s