动态类型语言与静态类型语言 [英] Dynamic type languages versus static type languages

查看:81
本文介绍了动态类型语言与静态类型语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与静态类型语言相比,动态类型语言的优点和局限性是什么?

What are the advantages and limitations of dynamic type languages compared to static type languages?

另请参见:对...的热爱动态语言(更具争议性的线程...)

See also: whats with the love of dynamic languages (a far more argumentative thread...)

推荐答案

解释器推断类型和类型转换的能力使开发时间更快,但也会引发运行时失败,而这是静态类型语言无法实现的在编译时捕获它们的地方.但是,这些天来(以及很长一段时间以来),社区中一直在热烈讨论哪个更好(甚至永远都是这样).

The ability of the interpreter to deduce type and type conversions makes development time faster, but it also can provoke runtime failures which you just cannot get in a statically typed language where you catch them at compile time. But which one's better (or even if that's always true) is hotly discussed in the community these days (and since a long time).

对此问题的一个很好的看法是来自静态输入的位置可能需要的时候,动态键入:编程语言之间的冷战结束,由Microsoft的Erik Meijer和Peter Drayton撰写:

A good take on the issue is from Static Typing Where Possible, Dynamic Typing When Needed: The End of the Cold War Between Programming Languages by Erik Meijer and Peter Drayton at Microsoft:

静态类型的拥护者认为 静态打字的优点 包括较早发现 编程错误(例如,防止 将一个整数添加到布尔值), 更好的文档形式 类型签名(例如合并 参数的数量和类型 解析名称),获得更多机会 用于编译器优化(例如 通过直接替换虚拟呼叫 调用时,确切的类型 接收者是静态已知的), 提高运行时效率(例如,不提高 所有的价值都需要带有动感 类型),并缩短设计时间 开发人员的经验(例如,了解 接收器的类型,IDE可以 显示所有的下拉菜单 适用的成员).静态打字 狂热分子试图让我们相信 类型良好的程序不会出错". 虽然这听起来肯定 令人印象深刻,这是一个真空 陈述.静态类型检查是 的编译时抽象 程序的运行时行为,以及 因此它必然只是部分 健全和不完整.这意味着 程序仍然会因为以下原因而出错 无法跟踪的属性 类型检查器,并且有 程序虽然无法执行 错误不能进行类型检查.这 减少静态打字的冲动 部分和更完整的原因类型 系统变得过于复杂 概念所见证的异国情调 例如幻像类型" [11]和 摇摇欲坠的类型" [10].就像 试图用球跑马拉松 和绑在你腿上的链子和 胜利地喊着你差点 即使你保释了也做到了 在第一英里之后.

Advocates of static typing argue that the advantages of static typing include earlier detection of programming mistakes (e.g. preventing adding an integer to a boolean), better documentation in the form of type signatures (e.g. incorporating number and types of arguments when resolving names), more opportunities for compiler optimizations (e.g. replacing virtual calls by direct calls when the exact type of the receiver is known statically), increased runtime efficiency (e.g. not all values need to carry a dynamic type), and a better design time developer experience (e.g. knowing the type of the receiver, the IDE can present a drop-down menu of all applicable members). Static typing fanatics try to make us believe that "well-typed programs cannot go wrong". While this certainly sounds impressive, it is a rather vacuous statement. Static type checking is a compile-time abstraction of the runtime behavior of your program, and hence it is necessarily only partially sound and incomplete. This means that programs can still go wrong because of properties that are not tracked by the type-checker, and that there are programs that while they cannot go wrong cannot be type-checked. The impulse for making static typing less partial and more complete causes type systems to become overly complicated and exotic as witnessed by concepts such as "phantom types" [11] and "wobbly types" [10]. This is like trying to run a marathon with a ball and chain tied to your leg and triumphantly shouting that you nearly made it even though you bailed out after the first mile.

倡导动态类型 语言认为静态类型是 太僵硬了,那柔软的 动态语言使它们 非常适合原型系统 在需求变化或未知的情况下, 或与其他系统互动 发生不可预测的变化(数据和 应用程序集成).当然, 动态类型的语言是 真正应对必不可少的 动态程序行为,例如 方法拦截,动态加载, 移动代码,运行时反射等. 在所有论文的母亲中 John Ousterhout认为脚本[16] 静态类型的系统 编程语言使代码更少 可重复使用,更冗长,更不安全, 表现力不及动态 键入脚本语言.这 从字面上看,论点受到许多人的模仿 动态类型的支持者 脚本语言.我们认为 这是一个谬论,属于 与争论的类别相同 声明式编程的本质是 消除分配.或作为约翰 休斯说[8],这是合乎逻辑的 无法增加一种语言 通过省略功能来实现强大功能. 捍卫一切延误的事实 对运行时进行类型检查是一个很好的选择 东西,在玩鸵鸟战术 应该发现错误的事实 在开发过程的早期 可能.

Advocates of dynamically typed languages argue that static typing is too rigid, and that the softness of dynamically languages makes them ideally suited for prototyping systems with changing or unknown requirements, or that interact with other systems that change unpredictably (data and application integration). Of course, dynamically typed languages are indispensable for dealing with truly dynamic program behavior such as method interception, dynamic loading, mobile code, runtime reflection, etc. In the mother of all papers on scripting [16], John Ousterhout argues that statically typed systems programming languages make code less reusable, more verbose, not more safe, and less expressive than dynamically typed scripting languages. This argument is parroted literally by many proponents of dynamically typed scripting languages. We argue that this is a fallacy and falls into the same category as arguing that the essence of declarative programming is eliminating assignment. Or as John Hughes says [8], it is a logical impossibility to make a language more powerful by omitting features. Defending the fact that delaying all type-checking to runtime is a good thing, is playing ostrich tactics with the fact that errors should be caught as early in the development process as possible.

这篇关于动态类型语言与静态类型语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆