From: Tom Sawyer Date: 2002-07-11T17:58:34+09:00 Subject: Re: String#split converts string args to regexes -- ? stepan, i think you should read this: > Imagine this... > > There is a 16compat.rb file in ruby1.8 lib directory. By requiring > it, all language features that have been changed (not added) in 1.8 > assume 1.6 behaviour. You could put a require 'compat16' in your > script, and you would be sure that, if it ran under 1.6, it will run > for you. You could even set that system-wide to be sure (e.g. `ruby' > is really a script containing `ruby -rcompat1.6') and require > 'compat18' for new projects. Most important, by doing so on the new > project, whatever change will happen in ruby2.0 you already know your > script will still run because compat18.rb in ruby2.0 will take care of > it... > > Just a thought. > > Massimiliano ~transami On Thu, 2002-07-11 at 02:30, Stepan Kasal wrote: > Hallo, > > > Quick reminder, for reference :-) > > > > sub/gsub > > > > (a) prohibit string pattern > > (b) string patterns as strings, without converting into regex. > > > > split > > > > (c) prohibit string pattern longer than 1. > > (d) string patterns as strings, without converting into regex. > > > On Wed, 10 Jul 2002, Stepan Kasal wrote: > > > So I vote for a-c, with an error message saying something like > > > "use either Regexp.new(s) or Regexp.new(Regexp.quote(s)) to clarify" > > On Wed, 10 Jul 2002 12:35:54 GMT, David Alan Black wrote: > [...] > > It's partly a matter of documentation stating that String#split takes > > a string or a regex, without (anywhere I've seen) noting that the > > string has to be only one character long or else has to follow regex > > syntax (because it's really a regex). > > > > I'm not sure what the disadvantage of allowing a string argument is. > > The disadvantage is that people will often write "error[.]log", hoping > that this will match the string "error.log". The reason for writing this > is not only the habit inherited from other languages, it may be simply > a program which used to work in a previous version of Ruby (though it > should not, according to the docs ;-). > > How would you like if a review of a new version of Ruby said this: > > We experienced non-complete backward compatibility with this > version, at least. Our old programs just stopped working, though > no error message appeared. We traced this down to a > (mis-)behaviour of the split() function. [...] > We recommend reviewing all your programs carefully before upgrading > Ruby, especially in a production environment. > > I know, similar reasoning applies to my solution (a-c with an error message), > at least to an extent, because the error is detected in runtime, so it may > last some time till the surprise appears. But I think crashing programs > is better then changing the semantics of old programs in a weird way. > > > It's not mandatory -- you can always use a regex (or even > > Regexp.new(s) :-) -- so allowing strings (without auto-conversion to > > regex) doesn't take away any functionality. > > I think that arguments like this one lead to non-elegant non-readable > languages. > > Stepan > -- ~transami "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -- Benjamin Franklin