3 ms·
"A variable can be anything" isn't loose typing. It's just that the type expressions that describe the program are not (necessarily) compile-time constant expre
by kazinator 12y ago
"A variable can be anything" isn't loose typing. It's just that the type expressions that describe the program are not (necessarily) compile-time constant expressions.
In many "variable can be anything" languages, you cannot for instance add the character string "3" to the number 3 to obtain 6. You get an error, like "the string '3' is not an arithmetic operand".
So even though the variable which holds that "3" can be anything, the arithmetic add operation doesn't take any kind of value.
Languages of this type can be subject to static checking, which can identify potential programs. Mature dynamic languages have good compilers with such checks. Instead of being told "you cannot run this program because of such and such a type mismatch", you get a softer diagnostic like "there is probably a type mismatch here". (And if the program is run anyway, the mismatch is still caught at run time and turned into an exception---if the execution of the program steps into the code with the values which trigger the problem.)