--------------enigD70D94F79B3DDCDFE39F4823 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Joe Ruby MUDCRAP-CE wrote: > One thing that annoys me about Ruby is that casting variables is > required: > > i = 5 > a = 'logan' > > puts a + i.to_s > > Or > > a='2' > b=3 > > puts a.to_i + b > > Why can't (or can?) Ruby just handle 'puts a + i' or 'puts a+b'? That's not type casting, that's type coercion. BIG difference. Language-level automagical number / string type coercion is a Perl / PHP -ism, and it's a feature of those languages I loathe and despise for the bugs it tends to cause. Numbers are numbers. Strings are strings. Strings that happen to represent numbers are still strings. Ruby is a strongly-typed language, a Very Good Thing from a code maintainability point of view, that's why type coercion is always explicit. Ruby sometimes does this on the library-function level, but in the examples you described, the meaning is always ambiguous. Especially since adding an integer to a string means the integer is considered to be the ASCII code of a character. If I do 'logan' + 115, does that mean I want the result to be 'logans' because 115 is the ASCII code for 's', should be 'logan115', or should it be just 115 because 'logan' isn't a number and thus automagically coerces to 0? And for '2' + 3 it gets even worse, which of those should be coerced to what and why? This is, in my opinion, best left explicit. The possible interpretations are way, way too numerous and difficult to keep in one's head at once. David Vallner --------------enigD70D94F79B3DDCDFE39F4823 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (MingW32) iD8DBQFFHsx8y6MhrS8astoRAnlBAJsFRWKFbdJsBPk1DYRLG6qOsG8h3wCfd84M I/v+KmtZntPrV1/1G3QO8Bk jk -----END PGP SIGNATURE----- --------------enigD70D94F79B3DDCDFE39F4823--