From: Robert Klemme Date: 2010-02-09T16:46:08+09:00 Subject: Re: Strings -- was: Re: Why Ruby? 2010/2/8 Marnen Laibow-Koser : > Brian Candler wrote: >> Seebs wrote: >>> Or is there something else in the new String that you don't like? >> >> It's as complex as hell. I took the trouble to document about 200 >> behaviours of String in 1.9, and I still haven't really scratched the >> surface. http://github.com/candlerb/string19/blob/master/string19.rb >> >> The scariest bit for me is that a simple expression like >> >>     a = b + c >> >> (where b and c are both Strings) can raise exceptions. > > So what? > >> Writing your >> program so that you can be *sure* it won't raise an exception is hard. > > Not at all.  That's what rescue is for. > >> Even the same program running on two different computers with the same >> version of ruby 1.9 and the same input data may crash on one but not on >> the other. >> >> I don't want to have to expend effort working around artefacts of the >> language, especially when dealing with binary data. > > Binary data doesn't belong in Strings.  Period.  The only reason you > have it in there in the first place is that 1.8's piss-poor String > handling allows you to treat strings as byte arrays. > > I haven't used 1.9 yet, so take this with a grain of salt, but my > impression is that encoding-aware Strings that aren't byte arrays is > exactly the right thing for Ruby to have. IMHO what 1.9 does better is the awareness of encoding. What it does worse IMHO is that binary is a special encoding of string and not a separate type (Java did it better here). Also, returning a String from String#[] with a single index does not seem the right thing to do. In this case I preferred the 1.8 solution - even better would be the Java solution to have a separate data type for characters. On one hand I can see how this all came about and class String is really versatile. On the other hand, it seems that String is growing overly complex. Maybe Ruby 2.0 should be used to clean this up and really separate handling of binary and character data. My 0.02EUR. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/