not safe at all
Grant Edwards
grante at visi.com
Fri Jul 13 10:04:12 EDT 2001
In article <mm8tkt4te3qnbpv3nh5nhsi591o1osln73 at 4ax.com>, Dennis Roark wrote:
>For amusement, run this little script which demonstrates a
>near ultimate in the lack of type safety in the language.
>(Perhaps there is a bit of type safety in that you can't do
>this: 4 + "one") But look at what you can do in the
>following script:
>
>x = 3
>x = x + 2
>print "x =", x
>x = "now I'm a string"
>print x
>x = [ 5, x ]
>print "and now a list:", x
>
>If you don't believe it, run it. Should any language allow
>x to be such a chameleon, to where it can even be a
>different type on two sides of an assignment?
You're laboring under a very fundamental misapprehension: x
doesn't have a type. x is a name. It is bound to an object.
That object has a type. You can bind the name x to any type of
object you wish.
If you want x to be bound to an integer, bind it to an integer.
If you don't want x to be a list, don't bind it to a list.
Did you realize that FORTRAN allows you to assign the _wrong_
value to a variable?
x = 1.234
WRONG! x is supposed to be 0.49487!
No language can prevent you from writing programs that yeild
incorrect results.
--
Grant Edwards grante Yow! I think my career
at is ruined!
visi.com
More information about the Python-list
mailing list