From: Brian Candler Date: 2010-11-25T00:15:28+09:00 Subject: Re: Ruby 1.8 vs 1.9 Michael Fellinger wrote in post #963539: >> from the environment, unless you explicitly code against that. This >> means the same program with the same data may work on your machine, but >> crash on someone else's. > > And that's why I use and love 1.9. > The obvious thing isn't so obvious if you actually care about > encodings, and if you are mindful about what comes from where, it's > actually helpful to find otherwise hidden issues. Y'know, I wouldn't mind so much if it *always* raised an exception. For example, say I have s1 tagged UTF-8 and s2 tagged ISO-8859-1. If "s1+s2" always raised an exception, it would be easy to find, and easy to fix. However the 'compatibility' rules mean that this is data-sensitive. In many cases s1+s2 will work, if either s1 contains non-ASCII characters but s2 doesn't, or vice-versa. It's really hard to get test coverage of all the possible cases - rcov won't help you - or you just cross your fingers and hope. You also need test coverage for cases where the input data is invalid for the given encoding. In fact s1+s2 won't raise an exception in that case, nor will s1[i], but s1 =~ /./ will. > I hear nobody complain that 1 / 0 raises but 1.0 / 0.0 gives Infinity, Well, IEEE floating point is a well-established standard that has been around for donkeys years, so I think it's reasonable to follow it. And yes, if I see code like "c = a / b", I do think to myself "what if b is zero?" It's easy to decide if it's expected, and whether I need to do something other than the default behaviour. Then I move onto the next line. For "s3 = s1 + s2" in 1.9 I need to think to myself: "what if s1 has a different encoding to s2, and s1 is not empty or s2 is not empty and s1's encoding is not ASCII-compatible or s2's encoding is not ASCII-compatible or s1 contains non-ASCII characters or s2 contains non-ASCII characters? And what does that give as the encoding for s3 in all those possible cases?" And then I have to carry the possible encodings for s3 forward to the next point where it is used. -- Posted via http://www.ruby-forum.com/.