phil_gg04@treefic.com writes:
[color=blue]
> The problems and potential bugs come when you have something that you
> think is a string, but it happens to contain only digits and so is a
> number:[/color]
A string containing only digits is still a string. The problem comes
when the programmer forgets what type the value is. It's a problem,
but it's not like the language changes strings to numbers without
telling you.
[color=blue]
> e.g. phone numbers, credit card numbers and so on. (Have you
> ever seem a program or web site strip leading zeros from a phone
> number? Or suffer an integer overflow when you enter 20 digits?).[/color]
That's because it's parsing the string into a number. It calls for
input validation, just as any other handling of user input, but
the type is not the problem.
[color=blue]
> Or, vice-versa, you think you have a number but actually have a
> string; this could easily happen if you have parsed a number out of
> a string with a regexp, for example, and it's difficult to debug
> because 'alert(x)' will give no clue.[/color]
Yep, if the programmer can't keep track of the types of his values,
Javascript is permissive enough to let him hang himself :).
It's one of the advantages of statically typed languages, that they
safeguard you from yourself.
[color=blue]
> The incident that I mentioned before was a long time ago and I forget
> the details, but it was to do with parsing CSS length units, i.e.
> splitting something like "10px" into a number (10) and a unit (px);
> instead of adding 1 to the length (11px) I ended up appending 1
> (101px).[/color]
A classic :).
[color=blue][color=green][color=darkred]
>>> I now use "-=-" for increment[/color][/color][/color]
Cute!
/L
--
Lasse Reichstein Nielsen -
lrn@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'