弱类型、强类型、动态类型、静态类型 1970-01-01 00:00

弱类型

A language in which types may be ignored; the opposite of strongly typed. VBScript is weakly typed. In VBScript, you can concatenate the string '12' and the integer 3 to get the string '123', then treat that as the integer 123, all without any explicit conversion.

强类型

A language in which types are always enforced. Java and Python are strongly typed. If you have an integer, you can't treat it like a string without explicitly converting it.

动态类型

A language in which types are discovered at execution time; the opposite of statically typed. VBScript and Python are dynamically typed, because they figure out what type a variable is when you first assign it a value.

静态类型

A language in which types are fixed at compile time. Most statically typed languages enforce this by requiring you to declare all variables with their datatypes before using them. Java and C are statically typed languages.

vczh 总结了一个简短的:

很多人说JavaScript坑,原因可能就是它既是动态类型又是弱类型的语言吧。

写了两三年动态语言(Python),越发喜欢强类型+静态语言+类型推倒的语言,比如swift和rust。

知乎上就有人吐糟:动态类型一时爽,代码重构火葬场。

到了代码上万行、多人协作的时候就真的深深体会到了。