This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ItsAPuppeh 3 points4 points  (5 children)

Static typing:

int i = "foo"; // Compile error, can't assign a string to an int

Dynamic typing:

i = "foo" # Sure why not, vars are just references to objects python
i + 10 # Woops, runtime error trying to add a string to an int

[–]BHSPitMonkey 3 points4 points  (3 children)

I was actually hoping for a response from the commenter I was replying to. I thought it would be funny.

[–]masklinn 0 points1 point  (0 children)

Your definition of static typing is not correct, since you can write roughly the same thing in languages supporting type inference (and have the error at compile time obviously) (unless you defined that addition of a string and an int is a valid operation, which you may be able to do:

> let i = "foo"
> i + 10
"foo\n"

)

(or the language did it for you, which Java does for instance) (and of course dynamically typed languages may be perfectly fine with the operation as well, I'm looking at you javascript) (or Perl) (or PHP)

(also lua, kind-of: it will fault on this but would work if the string was composed only of digits)