Hacker News new | ask | show | jobs
by dragonwriter 3778 days ago
> As to whether it is dynamically or statically typed - it's easy to tell - do you need to indicate a variable is an int or a char or a string before you start using it?

Modern statically typed languages often don't require this, because type inference, so its a bad test.

> and do you have to cast the variable to different types when using functions that expect a certain type?

Modern statically-typed languages may not require you to do this (e.g., Scala if the types involved have appropriate implicit conversions defined.)

> Dynamically typed languages allows you to give an character "5" to a function that expects an integer (ie the number 5) and then automatically converts it so for example the final result to 5+"5" is int(10).

That's the canonical example of weak typing; many (maybe most) dynamically-typed languages do not do this type of conversion.

A better test for a dynamically-typed language is what kind of error is produced by sending a value of an unexpected tpe (including, as expected, anything that can be handled by the applicable implicit conversion rules) to a function: if it is a compile-time error, the language is statically typed. If it is a runtime error, it is a dynamic language.