为什么 JavaScript 有时被视为低级语言?
受到这个问题的启发。
我经常看到人们将 JavaScript 称为低级语言,尤其是在 GWT 和类似工具包的用户中。
我的问题是:为什么? 如果您使用这些工具包之一,那么您就会失去一些使 JavaScript 非常适合编程的功能:作为对象的函数、动态类型等。尤其是与 jQuery 或 Prototype 等流行框架之一结合使用时。
这就像调用 C++ 低级一样,因为标准库比 Java API 小。 我不是 C++ 程序员,但我非常怀疑每个 C++ 程序员都会编写自己的 GUI 和网络库。
Inspired by this question.
I commonly see people referring to JavaScript as a low level language, especially among users of GWT and similar toolkits.
My question is: why? If you use one of those toolkits, you're cutting yourself from some of the features that make JavaScript so nice to program in: functions as objects, dynamic typing, etc. Especially when combined with one of the popular frameworks such as jQuery or Prototype.
It's like calling C++ low level because the standard library is smaller than the Java API. I'm not a C++ programmer, but I highly doubt every C++ programmer writes their own GUI and networking libraries.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
考虑到它的灵活性(作为对象的功能等),它是一种高级语言。
但是任何通常编译为的语言都可以被视为低级语言,因为它是编译的目标,并且 现在有很多语言可以编译为 JS,因为它作为浏览器的独特角色DOM 控制语言。
可以编译为 JS 的语言(或其子集)包括:
It is a high-level language, given its flexibility (functions as objects, etc.)
But anything that is commonly compiled-to can be considered a low-level language simply because it's a target for compilation, and there are many languages that can now be compiled to JS because of its unique role as the browser's DOM-controlling language.
Among the languages (or subsets of them) that can be compiled to JS:
用“它不是 X”来回答“为什么某物有时被称为 X...”的问题完全是在回避这个问题,不是吗?
对于许多人来说,“低级”和“高级”是灵活、抽象的概念,在使用不同的系统时会有不同的应用。 对于那些不完全沉迷于过去的人(对某些人来说,不存在现代低级语言这样的东西),语言的高级或低级通常指的是它与目标机器的接近程度是。 这包括虚拟机,现在的浏览器就是虚拟机。 对所有渴望在基础硬件上使用 asm 的人表示抱歉。
当您将浏览器视为虚拟机时,JavaScript 与您所得到的(假)硬件非常接近。 这就是许多称 JavaScript 为“低级”的人的观点。 我认为这种区分是毫无意义的,人们不应该纠结于什么是低什么是高。
Answering a question that says "why is something sometimes called X..." with "it's not X" is completely side stepping the question, isn't it?
To many people, "low-level" and "high-level" are flexible, abstract ideas that apply differently when working with different systems. To people that are not all hung up on the past (there is no such thing as a modern low-level language to some people) the high-ness or low-ness of a language will commonly refer to how close to the target machine it is. This includes virtual machines, of which a browser is now days. Sorry to all the guys who pine for asm on base hardware.
When you look at the browser as a virtual machine, javascript is as close to the (fake) hardware as you get. That is the viewpoint that many who call javascript "low-level" have. I think it's a pointless distinction to make and people shouldn't get hung up on what is low and what is high.
很多人这么说是因为 JavaScript 中提供的对象和结构非常简单。 要开发任何类型的实际功能,您必须使用外部库。 低级别是一个不好的表达方式,因为它在计算机科学中已经具有含义。 更好的说法可能是它没有内置库。
与 Java 相比,实际的语言实际上并没有做很多事情。 尝试在没有 ArrayList 的情况下创建数组,或者在没有 IO 库的情况下访问文件系统。 大多数语言不仅仅是基础知识,它们还具有额外的功能。
对于 JavaScript,我们获得的唯一真正的力量来自于浏览器引入的 API,这些 API 并不是该语言的一部分。 诸如 DOM 操作和 Ajax 之类的东西都是由浏览器提供的。
总结这一切可能更好的是,使用像 Java 这样的语言,您可以开始做一些严肃的工作,而无需下载第三方库,但是使用 JavaScript,您要么必须下载一个库,要么编写一个库你自己。
A lot of people say this because the objects and structures provided in JavaScript are about as simple as you can get. To develop any sort of real functionality, you have to use an external library. Low level is a bad way to put this, because it already has a meaning in computer science. A better way to say it may be that it's without built-in libraries.
Compare this with Java, where the actual language really doesn't do a whole lot. Trying making an array without an ArrayList, or access the file system without the IO libraries. Most languages are more than just the basics, they come with this extra functionality.
With JavaScript, the only real power we get comes from the APIs that are introduced by the browsers and aren't part of the language. Things like DOM manipulation and Ajax are supplied by the browser.
It may be better to summarize all of this by saying that with a language like Java, you can get started doing some serious work without having to download third-party libraries, but with JavaScript, you either have to download a library or write a library of your own.
这里的“低”与“第一次世界大战中的伤亡人数低”和“低脂冰淇淋热量低”的含义相同。 当有明显的比较点时,这是有道理的,但脱离上下文,这简直是荒谬的。
"Low" here has the same meaning as in the sentences "The number of casualties suffered in the first world war was low," and "Reduced-fat ice cream is low in calories." It makes sense when there's an obvious point of comparison, but out of context, it is simply absurd.
我不认为 javascript 是一种低级语言。 它提供了许多功能和用户体验增强器。 也许其他人可能会这样简单地认为它是因为用户可以在浏览器选项中将其关闭,但它是一种非常强大的语言,几乎可以在所有类型的浏览器上运行网络......
I don't view javascript as a low level language. A lot of functionality and user experience boosters are provided by it. Maybe others may view it as such simply because users can turn it off in their browser options, but it's a hugely robust language that virtually runs the web on virtually all types of browsers...
事实并非如此,它可能是普通浏览器编程中的最低级别,但它与像Scheme或Python这样的函数式语言相当。
我认为 Javascript 的最大缺陷是缺乏名称空间或包装以及没有线程
It's not, it may be as low-level as you can get in normal browser programming, but its on par with functional languages like Scheme or Python.
I think the great lacks of Javascript are lack of name spaces or packaging and no threads
与 GWT 和类似工具包相比,它是低级语言,但从更大的角度来看,它并不是一种低级语言。 它提供的功能非常高级:闭包、动态类型和原型继承只是其高级功能的几个示例。
It's low-level compared to the GWT and similar toolkits, but it's not a low-level language in the larger scheme of things. The features it offers are very high-level: closures, dynamic typing, and prototypical inheritance are just a few examples of its high-level features.
许多更喜欢编写 java 来生成 javascript 而不是编写 javascript 的人认为这是低水平的(即他们公平或不公平地不喜欢它)。 现在很多人抱怨 java,但尽管缺乏静态类型检查,大多数人可能会认为 ruby 和 python 在大多数情况下更容易编写(java 是一种相当简单的静态语言 - 如果没有大型构建,很难很好地设计) -在功能集中然后是简单的动态语言)。
与 java 相比,很少有人会认为 python 或 ruby 是低级的,如果人们被迫以 python 或 ruby 虚拟机为目标,很难想象 java 到 python/ruby 的编译器会像 gwt 一样流行。
最后,JavaScript 有一个图像问题(人们有时认为语言变得越来越困难,因为它们变得更底层,反之亦然)。
It's considered to be low level by a number of people who prefer writing java to generate javascript then writing javascript(ie they dislike it fairly or unfairly). A lot of people complain about java these days but despite the lack of static type checking most people would probably consider ruby and python easier to write in most cases (java being a fairly simple static language-which are much harder to design well without large built-in feature sets then a simple dynamic language).
Few people would call python or ruby low level compared to java and if people were forced to target a python or ruby vm its hard to imagine that a java to python/ruby compiler would become as popular as gwt.
In closing javascript has an image problem(people sometimes think of languages as getting more difficult as they become more low level and vice versa).