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.
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”
[…]
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
···
On Wed, 10 Jul 2002, Stepan Kasal wrote:
On Wed, 10 Jul 2002 12:35:54 GMT, David Alan Black wrote: