Dart 语言相对于 JavaScript (Node.js) 的优势是什么
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7712107/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the benefit of the Dart language over JavaScript (Node.js)
提问by Phil Hannent
I don't see the point of Dartin terms of the problem they are trying to solve.
我没有看到Dart试图解决的问题的意义。
I read that it was created due to short comings of JavaScript, however those short comings were not given.
我读到它是由于 JavaScript 的缺点而创建的,但是没有给出这些缺点。
Can someone explain the benefit of learning Dart rather than me learning Node.js?
有人可以解释学习 Dart 而不是我学习 Node.js 的好处吗?
采纳答案by Joachim Sauer
The technical overviewseems to summarize the difference quite well:
该技术概述似乎总结的区别相当不错:
classes: while JavaScript isobject oriented and it does notprovide classes (at least in its latest incarnations), it is really a prototype-based language and not a class-based language. While that is not inherently worse, it is different from most major OO languages, which makes it harder to learn for most people.
(optional) static typing: You can't do static typing (as in: "checked by the compiler") in plain JavaScript. The advantages (and disadvantages) are well-known and have been widely discussed.
language support for libraries: "loading that file before this" is a very primitive way of implementing libraries and mostmodern languages have explicit support for libraries in some way.
类:虽然 JavaScript是面向对象的并且不提供类(至少在其最新版本中),但它确实是一种基于原型的语言,而不是基于类的语言。虽然这本身并不是更糟,但它与大多数主要的面向对象语言不同,这使得大多数人更难学习。
(可选)静态类型:您不能在纯 JavaScript 中进行静态类型(如:“由编译器检查”)。优点(和缺点)是众所周知的,并已被广泛讨论。
库的语言支持:“在此之前加载该文件”是实现库的一种非常原始的方式,大多数现代语言都以某种方式明确支持库。
That page also mentions tooling, but that's not an inherent difference between languages. Granted, a statically compiled and typed language is easierto write good tools for, but this is not a fundamental difference that can't be solved by programming.
该页面还提到了工具,但这不是语言之间的固有差异。诚然,静态编译和类型化语言更容易为其编写好的工具,但这并不是编程无法解决的根本区别。
回答by Chris Buckett
The main issue I see it as solving that of creating large, multi-developer applications.
我认为它的主要问题是解决创建大型、多开发人员应用程序的问题。
In Javascript, I can write the perfectly valid code:
在 Javascript 中,我可以编写完全有效的代码:
function x(y) {
return y*y;
}
document.write(x(3,4,5));
And this will execute fine, but it's blatantly an error.
这将执行得很好,但这显然是一个错误。
Now separate the function definition and the function call by several developers and several months over a codebase of several thousand lines of code.
现在,在几千行代码的代码库中,将几个开发人员和几个月的函数定义和函数调用分开。
The original function x(y) could have originally been function x(y,z,a) but has since been refactored over time. This is where javascript fails for me, and this is what dart will help resolve.
原来的函数 x(y) 本来可以是函数 x(y,z,a) 但后来随着时间的推移被重构了。这就是 javascript 对我来说失败的地方,这就是 dart 将帮助解决的问题。
Edit (May 2013)In addition to my answer above, which I believe still holds true, I think that the performance story is also getting pretty compelling. Lars Bak and Kasper Lund's talk from Google I/Oprovides some evidence.
编辑(2013年5 月)除了我上面的回答(我认为仍然适用)之外,我认为表演故事也变得非常引人注目。Lars Bak 和 Kasper Lund在 Google I/O 上的谈话提供了一些证据。