Unlike Perl and PHP, both Python and Ruby don't allow you to convert strings implicitly to numbers like this, instead demanding that you explicitly convert them (by calling int() in Python and the to_i() method in Ruby). Curiously, Ruby's to_i() method, a la Perl and C's atoi(), happily converts "2abc" to the integer 2, while Python's stricter int() function instead issues a run time error. I know about all this from playing too much multi-language golf. :- ) In golf, these explicit conversions are certainly a chronic pest. In normal programming, however, I don't feel strongly -- though I suspect demanding explicit conversion may help the programmer avoid some data conversion boo boos.
What's implicit about using numeric operators on strings? If you use string operators on strings, you get string behavior. If you use numeric operators (which you must do explicitly), you get numeric behavior. What isn't explicit about that?
Yes, I guess it is explicit in Perl.
In terms of language design, the interesting question is whether the Python/Ruby demand to
explicitly cast/coerce by calling int is "stronger/safer typing"
or "ugly explicit casting" (frowned upon in C++, for example). Let's clarify with a little test program.
In Perl, running:
my $x = "2abc";
my $y = $x + 42;
print "x=", $x, " y=", $y, "\n";
Ruby's to_i method being less strict than Python's int function.
I guess Ruby and Python need to do it that way because the + operator is overloaded for both numeric addition and string concatenation, while Perl has a separate string concatenation operator, and so there is no ambiguity.
Update: Python's stricter typing can produce other subtle differences. For example, in Python both 5 * "X" and "X" * 5 produce five Xs. Not so in Perl or Ruby. That is, the string multiply operator is commutative in Python, but not in Perl or Ruby. Not sure if string multiply commutativity is a bug or a feature. Curiously, the new Perl 5.10 smart match operator ~~ was commutative in Perl 5.10.0, then that was deemed a mistake and it was made non-commutative in Perl 5.10.1.