Screencasts

Some discussion about software related screencasts.

2

JUL
2009

Getting Ready for Ruby 1.9

We've all been waiting for Ruby 1.9 to reach maturity for some time now. We've complained about things like Ruby's speed and weak character encoding support. We knew 1.9 could improve things, but it brings pretty big changes and a lot of Ruby 1.8 code needs updating before it can really be used there. For these and other reasons, the official production release came and went while most of us have stuck with 1.8 for our day to day needs.

I think we're reaching the tipping point though. Rails runs on 1.9 now and many other libraries are beginning to become compatible. We may not yet have the full range of 1.8 goodies available on the new platform, but many of the staples are moving over and it's looking like we can now do some serious work there.

Which means it's finally time for us to learn this 1.9 stuff.

There are several good sources of Ruby 1.9 information now, so you have choices. I'm going to tell you about three I like. Be warned, this is a super biased list, but I really hope it will be helpful to others.

My first recommendation is based on simple math: watch the Ruby 1.9 envycasts. It costs $16 and eats about an hour and fifteen minutes of your time. However, it pays you back with covering about 80% of what you need to know about Ruby 1.9. That's absurdly cheap, if you ask me.

These two screencasts are quite well done. You are in the very capable hands of host David A. Black, as he guides you through syntax changes, updates to the core collection classes of Hash, Array, String, and Enumerable, plus several new features including the adoption of Enumerator into the core, block local variables, and more. It's a content packed hour, for sure. It also includes the best description of the multiple assignment changes in Ruby 1.9 I have yet encountered.

Of course, nothing is perfect. I can add a few minor complaints about this series. First, David sometimes mentions syntax that has been removed without covering alternatives. For example, he mentions that : is no longer a valid way to jam an if or case condition on the same line with the code to execute when it matches, but he fails to mention that then still works for the same use. Similarly, he tells you that you can no longer build a Hash with {1, 2, 3, 4} (note the commas instead of using the arrow operator), but he doesn't mention Hash[1, 2, 3, 4]. That's unfortunate to me since the latter method has a nice upgrade in Ruby 1.9 and will now accept associative Array arguments: Hash[[[1, 2], [3, 4]]]. David is also careful to avoid some of the bigger new topics like Fibers, the Oniguruma regular expression engine, and most of the m17n functionality. That's pretty much a given due to the scale of his offering, and he freely admits that, but it does mean this isn't going to turn out to be the only 1.9 resource you will need. Finally, the videos are missing the excellent chapter headings that I've found so useful in using Peepcode and Pragmatic Screencasts as reference material. It's important to stress that these are all minor issues and both videos are very worth a watch.

At the risk of being called a traditionalist, my second recommendation is going to be the classic advice Rubyists tend to give: grab a copy of the new Pickaxe. There are some other options for a Ruby reference now and they are good. However, the Pickaxe is still the best choice, in my opinion. There's no other single source that provides an introduction to the language, all 1.9 syntax changes, details about Fibers and Oniguruma, new methods from the popular Object#tap() to the lesser known Process::daemon(), and all the cool additions to the standard library like ripper, json, or even just the improvements to shellwords. Its m17n coverage isn't quite as in-depth as mine, but it's very serviceable and probably a lot less intimidating to the casual reader. The Pickaxe really is one stop shopping and that's why I can't live without it.

For my final suggestion, I'll go with something fun: come learn Ruby 1.9 in an all-day workshop run by Dana and myself at Lone Star Ruby Conference 2009! I ran an I/O training at last year's conference which turned out great in spite of all my first time trainer mistakes. I've used what I learned there to plan a much better session for this year. That includes bringing Dana on board as my partner, since she has years of experience doing these trainings. Pat Eyler recently interviewed us about our workshop, so check that out for more details on what we have planned. You can even stay for the rest of LSRC!

Whatever path you choose, it's time to start getting up to speed on Ruby 1.9. If nothing else, install it along side your 1.8 interpreter and start trying things out in it. Start getting familiar with it and see what it's still lacking for your personal needs, if anything. The sooner we complete this transition, the better things will be for all of us.

Comments (6)
  1. James Healy
    James Healy July 2nd, 2009 Reply Link

    I spent a day last month getting the main Rails 2.3 app I support into shape for 1.9.

    At first I was pleasantly surprised - once I'd patched a couple of gems it more or less seemed to work.

    Then I tried to submit a form with UTF-8 data and got an exception. Rack was marking my input data as ASCII-8BIT and it was causing an exception when I attempted to combine it with a UTF-8 string in my controller.

    Then I attempted to view a page that was pulling UTF-8 data from the MySQL database. The MySQL driver also marks all strings as ASCII-8BIT and causes the same issues.

    Then I attempted to embed a UTF-8 string from my controller in an ERB template and the same thing happened, since erb is apparently encoding unaware.

    Looks like there's still a few libraries to be updated before I can run my Rails app on 1.9 :)

    1. Reply (using GitHub Flavored Markdown)

      Comments on this blog are moderated. Spam is removed, formatting is fixed, and there's a zero tolerance policy on intolerance.

      Ajax loader
    2. elliottcable
      elliottcable July 3rd, 2009 Reply Link

      Two things:

      • First of all, to make it abundantly clear: Ruby 1.9 is, and has been, official for a while. To anyone reading this, if you haven’t switched… well, you should have. So go do it. Now. It’s not difficult to run Ruby 1.9 and Ruby 1.8 side–by–side for testing purposes; if you really feel the need to continue to support Ruby 1.8, you can easily do so.

      • Second: James, regarding encodings, I’m going to go out on a limb a little bit and suggest that the problems you describe are more user error than problems with the libraries you mentioned. I don’t use Rails or any of the things you mentioned, but it’s very much to your benefit to be explicit about encodings. If you’re storing data in your database as 'UTF–8', tell Ruby this. Don’t expect it to know it. 'ASCII-8BIT' is the default in many places where Ruby thinks your data is, for whatever reason, binary—there’s quite a few tricks you can use to ensure your strings come out with the correct Encoding attached.

      1. Reply (using GitHub Flavored Markdown)

        Comments on this blog are moderated. Spam is removed, formatting is fixed, and there's a zero tolerance policy on intolerance.

        Ajax loader
      2. James Healy
        James Healy July 4th, 2009 Reply Link

        Hi Elliott,

        "If you’re storing data in your database as 'UTF–8', tell Ruby this"

        With respect, can you point to the option in current versions of Rack, MySQL/Ruby or ERB that allow me to "tell Ruby" what encodings strings should be in?

        If you can, I'll eat my hat.

        I've never suggested the Ruby VM should magically know what encoding my strings are in. My point is just that some of the core libraries we use still need to be upgraded to be encoding aware before it's realistic for us to switch to 1.9 in production.

        1. Reply (using GitHub Flavored Markdown)

          Comments on this blog are moderated. Spam is removed, formatting is fixed, and there's a zero tolerance policy on intolerance.

          Ajax loader
    3. Ivan Schneider
      Ivan Schneider July 6th, 2009 Reply Link

      Same here. Tried to upgrade a production app running on Ruby 1.8.6 / Rails 2.3.2 to Ruby 1.9. I added the magic comments to my controllers and then got stuck with my views containing utf-8 characters. I found a patch on the Rails lighthouse which seems to be meant to fix the problem but I got used to Rails working out of the box and I don't want to start running production apps with a patched version of Rails.

      1. Reply (using GitHub Flavored Markdown)

        Comments on this blog are moderated. Spam is removed, formatting is fixed, and there's a zero tolerance policy on intolerance.

        Ajax loader
    4. Thomas Glasgow
      Thomas Glasgow July 3rd, 2010 Reply Link

      3rd of july 2010, and this problem still hasn't been addressed.

      Running Rails 2.3.8 and Ruby 1.9.1 still produces this error. Adding magic comments fixes some areas, but it still falls to bits and pieces elsewhere.

      1. Reply (using GitHub Flavored Markdown)

        Comments on this blog are moderated. Spam is removed, formatting is fixed, and there's a zero tolerance policy on intolerance.

        Ajax loader
      2. James Edward Gray II

        Yes, I'm afraid I can't recommend Ruby 1.9 with Rails yet. We are running it in production, but we have it heavily patched (which isn't a great idea, of course).

        1. Reply (using GitHub Flavored Markdown)

          Comments on this blog are moderated. Spam is removed, formatting is fixed, and there's a zero tolerance policy on intolerance.

          Ajax loader
Leave a Comment (using GitHub Flavored Markdown)

Comments on this blog are moderated. Spam is removed, formatting is fixed, and there's a zero tolerance policy on intolerance.

Ajax loader