On 8 February 2010 21:12, Brian Candler <b.candler / pobox.com> 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. Writing your > program so that you can be *sure* it won't raise an exception is hard. > 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. The complexity stems from the inherent issues of handling strings in multiple encodings. In 1.8 the support was nearly non-existent. In 1.9 the support is improved at the cost of increased complexity. I think it would be nice if somebody wrote a library that adds autoconversion to strings. While it's not hard to hack the support for a particular piece of code doing it as a general library would probably require a bit of thinking, especially since we still don't have namespaces. You can't do much better than what 1.9 has. In 1.8 a = b + c was guaranteed to not throw an exception but it could easily produce complete nonsense as result in exactly the cases where 1.9 would throw an exception. Obviously, you can override the 1.9 + method to do a conversion automatically instead and face the consequences if the encoding information in the string was wrong. I agree that having to deal with this for binary data as well is the somewhat unfortunate result of sharing the string class for both text strings and binary data. The upside of such sharing, especially in 1.8 which lacked the subtyping of String by encoding was the ability to interpret binary data as text when looking for textual magic such as GIF89a. You can't have everything at once. A simple solution fails for some more complex problems, a more complete solution has to be set up for any particular simple case. Thanks Michal