[科普]So what is “strong typing”?
发布于 9 年前 作者 JexCheng 3773 次浏览 最后一次编辑是 8 年前 来自 分享

想必很多人都搞不清楚强类型、弱类型、静态类型、动态类型这些概念,网上很多博客的说法都不太准确。 下面的图表清楚地划分了这些概念,从图上看,静态类型、动态类型大家应该明白其实是指的type sound check发生的时机。而强类型、弱类型到底是什么意思呢?其实这些词语本身概念就是模糊不清的,反正我是能避免使用就尽量避免使用。 《Programming Language:Application and Interpretation》 type.png

So what is “strong typing”? This appears to be a meaningless phrase, and people often use it in a non- sensical fashion. To some it seems to mean “The language has a type checker”. To others it means “The language is sound” (that is, the type checker and run-time system are related). To most, it seems to just mean, “A language like Pascal, C or Java, related in a way I can’t quite make precise”. If someone uses this phrase, be sure to ask them to define it for you. (For amusement, watch them squirm.)

4 回复

搜到知乎一篇文章,补充过来:http://www.zhihu.com/question/19918532

@alsotang 我觉得他的区分还是不够简明易懂,而且我看到这种定义已经让评论里的一些人产生了误解,比如:

  • 如果在编译时拒绝ill behaved程序,则是statically typed;
  • 如果一种语言的所有程序都是well behaved,则该语言为strongly typed。

有人推理认为,所有statically typed都一定是strongly typed,或者weakly typed不可能是statically typed,因为它可能出现forbidden behaviors。

这里的问题在于:在编译时拒绝(不是全部)ill behaved是编译器的行为,并不是说:ill behaved程序 不属于 该程序语言子集,不是概念上的定义。所以这种定义还是不易理解,事实上可以这么说,并不存在statically typed,只有statically checked,因为它不是语言固有属性,而是编译期的行为,搞清这点就不会产生误解了。


可能仍然还是有人会产生一些误解,比如说statically typed不是语言固有属性,那C\C++、Java的类型声明又怎么解释呢?那叫“Explicitly Typed”,类型是语言语法的一部分,但是静态检查还是运行期检查还是根本不检查,那就是编译器的行为了,比如PHP有Type Hint,看上去就像Explicitly Typed,但它是运行到那行代码才检查,仍然不是statically checked

PS: CNodeJS 提交时太卡了,我提交一次要等近一分钟才返回

@JexCheng 你的网络环境是?我不翻墙访问都还蛮快的。

@alsotang 上传文件有时timeout,有时502。打开帖子有时也是“Can not get /topic/xxxx/”,应该是服务器太忙了

回到顶部