Upgrading to Ruby 1.9 - Should I? Is it painful?

Hi All,

I recently encountered a problem while trying to install the Nesta CMS
gem, and the only answer I found so far to a similar problem is,
“upgrade to Ruby 1.9”.

Now since upgrading to 1.9 is something I wanted to do anyway (my
sysadmin upbringing tells me to always strive to be at the latest
release), I wonder if you could tell me if this is really a hassle or
not.

My code is pretty straightforward but it uses CouchPotato and I am going
to use it with Nesta, so I especially wonder about what happens with all
those gems.

So should I upgrade? and if yes, how do I go about it? is there any
upgrade user guide anywhere that can tell me what to watch out for in
the code? Can someone share some tips and tricks?

Many thanks

Oren

On Thu, Apr 12, 2012 at 3:54 AM, Oren S. [email protected]
wrote:

“upgrade to Ruby 1.9”.

So should I upgrade? and if yes, how do I go about it?

Yes – install ‘Ruby Version Manager’ (rvm) from https://rvm.io/

Then you can run your tests using the latest Ruby, experiment with
different sets of gems, etc. as necessary.

Oren S. wrote in post #1056125:

Now since upgrading to 1.9 is something I wanted to do anyway (my
sysadmin upbringing tells me to always strive to be at the latest
release), I wonder if you could tell me if this is really a hassle or
not.

IME it’s pretty painful, in particular if you have programs which use
Strings, and you want to understand how they work in ruby 1.9. Here’s my
attempt:

Personally I find that ruby 1.9 is a very different and painful
language, so I stick with 1.8. YMMV.

If you are going to 1.9 then also check that all the gems/libraries you
use work with 1.9.

Job: PHP developer needed to work for cool, well-provisioned startup.
Work on-site or remotely. Lots of JS and front-end work, along with some
CodeIgniter backend.

DON’T REPLY TO THIS EMAIL (LIKE I ALWAYS DO) !!

Instead, get in touch with me here: [email protected]

W dniu 16 kwietnia 2012 22:05 użytkownik Brian C.
[email protected] napisał:

IME it’s pretty painful, in particular if you have programs which use
Strings, and you want to understand how they work in ruby 1.9.

As much as I admire Brian’s work on documenting 1.9’s String behavior,
you will be fine on 1.9 if you stick to two rules:

  1. Always use UTF-8 internally. Encode your source files as UTF-8 and
    add #coding: magic comments to every file. Make sure any data files
    are in UTF-8 too. This will help you and everyone reading your code in
    the future, not just Ruby.
  2. Always immediately convert any incoming data to UTF-8. Sensible
    frameworks should already do it for you, but mind it if rolling your
    own. Use code like File.open(‘asd.txt’, ‘r:utf-8’) if necessary. (E.g.
    if it doesn’t work without the utf-8 part.)
    (3.) Optionally, if possible, switch to an operating system that is
    UTF-sane in the console. (Windows, I’m looking at you…) (Although my
    primary environment is Windows and I have no troubles with it, save
    for occasionally having to encode stuff as CP852 for printing to
    console.)

– Matma R.

W dniu 18 kwietnia 2012 00:46 użytkownik Brian C.
[email protected] napisał:

File.open(‘asd.txt’, ‘r:utf-8:iso-8859-1’)

Yes, thank you for correction. My point still stands.

The fundamental point with ruby 1.9 is that every String is a
two-dimensional vector of bytes + encoding. There are some circumstances
in which Strings which contain invalid characters (according to their
declared encoding) work, and others in which they don’t. There are some
circumstances in which Strings with different encodings can be combined,
and others when they can’t.

That’s unfortunately extremely true. Keeping everything UTF-8 makes
all of these problems disappear.

– Matma R.

On Apr 18, 2012, at 12:46 AM, Brian C. wrote:

File.open(‘asd.txt’, ‘r:utf-8:iso-8859-1’)

The fundamental point with ruby 1.9 is that every String is a
two-dimensional vector of bytes + encoding. There are some circumstances
in which Strings which contain invalid characters (according to their
declared encoding) work, and others in which they don’t. There are some
circumstances in which Strings with different encodings can be combined,
and others when they can’t.

Have fun trying to understand it.

The fundamental problem is that you can only guess what the external
world
looks like as input streams have no encoding. The problem exists in Ruby
1.8
as well - its just not as visible.

In practice though, I rarely have any problems, only when dealing
with systems that are messy with respect to encoding in the first place.

Best regards,
Florian

Bartosz Dziewoński wrote in post #1056782:

  1. Always immediately convert any incoming data to UTF-8. Sensible
    frameworks should already do it for you, but mind it if rolling your
    own. Use code like File.open(‘asd.txt’, ‘r:utf-8’) if necessary. (E.g.
    if it doesn’t work without the utf-8 part.)

Note: that doesn’t actually “convert incoming data to UTF-8”. It just
labels incoming data as being UTF-8, whether it is or not. If you want
to convert data, you have to provide both the target and original
encodings, e.g.

File.open(‘asd.txt’, ‘r:utf-8:iso-8859-1’)

The fundamental point with ruby 1.9 is that every String is a
two-dimensional vector of bytes + encoding. There are some circumstances
in which Strings which contain invalid characters (according to their
declared encoding) work, and others in which they don’t. There are some
circumstances in which Strings with different encodings can be combined,
and others when they can’t.

Have fun trying to understand it.