[Rails] 12 / 16 = 0
Jonathan Weiss
jw at innerewut.de
Sun Apr 2 09:53:43 GMT 2006
>
> That's the kind of answer I was looking for. So I can definitely see why
> strongly typed languages are safe and predictable and all, but why
> (just out of interest) does PHP (and in the future phython?) have it?
I can't comment about Python but PHP is like Perl weakly typed.
So in PHP/Perl
5 + "6" results in 11
While in Ruby (or e.g. Java) you have to say
5 + "6".to_i results in 11
Weakly typed languages do so because this behavious is somethimes handy
as you save some characters as you do not have to explicitly convert types.
The problem is that this can become dangerous when you didn't want the
autoconversion but forgot to explicitly tell the interpreter. Especially
if one part of the input comes from the user. Say hello to many kinds of
user injected code like SQLinjection or other malicious behaviour.
E.g. what is
5 + "6a" ??
Depending on the language it could be
11
"56a"
Or an exception. Now if it is the string "56a" and you really need a
number further down in your code?
Jonathan
--
Jonathan Weiss
http://blog.innerewut.de
More information about the Rails
mailing list