does lack of type declarations make Python unsafe?
marshall
marshall at spamhole.com
Tue Jun 17 00:16:21 EDT 2003
Alex Martelli <aleax at aleax.it> wrote in message news:<BUfHa.181518$g92.3608985 at news2.tin.it>...
[Quoting another thread]
> "To claim that the strong, static type checking constraints in C++, Java, or
> C# will prevent you from writing broken programs is clearly an illusion
> (you know this from personal experience). In fact, what we need is
>
> Strong testing, not strong typing."
Most of the code I come across in strong typed languages makes heavy
use of type coercion. So how does typing help if you are just going
to coerce everything?
I was recently stung by this [apologies for VB code]:
Dim lDelaySec As Integer
Dim lDelayTicks As Double
lDelaySec = Fix(Val(Text1.Text))
lDelayTicks = lDelaySec * 1000
Text3.Text = Str(lDelayTicks)
Works fine for values of lDelaySec less than 32 but you get a buffer
overflow for larger values. I guess type checking would have caught
it for me but how stupid is it that I can't multiply an integer, enen
though I prepared for the fact that the result might be a double
(lDelaySec as an Integer was a given). So I have to coerce the result
- type checking does me no good anyway.
Marshall
More information about the Python-list
mailing list