JavaScript是Web的汇编语言:第2部分-疯狂还是疯狂?

UPDATE: Check out the Podcast I did with Erik Meijer on Hanselminutes this week on this very topic: JavaScript is Assembly Language for the Web: Semantic Markup is Dead! Clean vs. Machine-coded HTML.

更新:本周我在Hanselminutes上与Erik Meijer进行的播客就以下主题进行了探讨: JavaScript是Web的汇编语言:语义标记已死! 干净与机器编码HTML

Some folks think that saying "JavaScript is Assembly Language for the Web" is a totally insane statement. So, I asked a few JavaScript gurus like Brendan Eich (the inventor of JavaScript) and Douglas Crockford (inventor of JSON) and Mike Shaver (Technical VP at Mozilla). Here is our private email thread, with their permission.

有些人认为,“ JavaScript是Web的汇编语言”是完全疯狂的说法。 因此,我问了一些JavaScript专家,例如Br​​endan Eich(JavaScript的发明者),Douglas Crockford(JSON的发明者)和Mike Shaver(Mozilla的技术副总裁)。 这是我们的私人电子邮件线程,得到他们的许可。

Mike Shaver:

Mike Shaver

I've heard the comparison before, and I think it's mostly right. It ignores the amount of effort put into JS's developer ergonomics, though, since assembly is not designed to have a humane syntax (especially modern assembly).

我之前听过比较,但我认为基本上是正确的。 但是,由于汇编不是为了具有人性化的语法(尤其是现代汇编)而设计,因此它忽略了JS开发人员的人机工程学方面的工作量。

Brendan Eich:

布伦丹·艾希( Brendan Eich)

I said "JS is the x86 of the web" a couple of years ago [likely at JSConf], but I can't claim it's original. [Nick Thompson said it on Hacker News this year as well.]

几年前(可能在JSConf上)说过“ JS是Web的x86 ,但我不能说它是原始的。 [尼克·汤普森( Nick Thompson)也在今年的黑客新闻中表示了

The point is JS is about as low as we can go. But it also has higher-level facilities.

关键是JS尽可能低了。 但是它也具有更高级别的设施。

Shaver's right, assembly without a great macro processor is not good for programmers or safety. JS is. So the analogy needs some qualification or it becomes silly.

Shaver的权利,没有出色的宏处理器的汇编程序对程序员或安全性都不利。 JS是。 因此,类比需要一定的资格,否则会变得很愚蠢。

The mix of high-level functional programming and memory safety, with low-level facilities such as typed arrays and the forthcoming ES.next extension of typed arrays, binary data, make for a more powerful programming language than assembly, and of course memory safety is the first differentiator.

高级功能编程和内存安全性的结合,以及低级功能(如类型数组和即将面世的ES)。类型数组的下一个扩展,二进制数据,使汇编语言比汇编语言更强大,当然,内存安全是第一个差异化因素。

Douglas Crockford:

道格拉斯·克罗克福德( Douglas Crockford)

I think it is a little closer to the mark to say that JavaScript is the VM of the web. We had always thought that Java's JVM would be the VM of the web, but it turns out that it's JavaScript.

我认为说JavaScript是Web的虚拟机还差一点。 我们一直认为Java的JVM将是Web的VM,但事实证明它是JavaScript。

JavaScript's parser does a more efficient job of providing code security than the JVM's bytecode verifier. JavaScript did a better job of keeping the write once, run everywhere promise, perhaps because it works at a higher level, avoiding low level edge cases. And then Turing takes care of the rest of it.

JavaScript的解析器在提供代码安全性方面比JVM的字节码验证程序做得更有效。 JavaScript可以更好地保持一次写入,可以在任何地方运行,这可能是因为JavaScript在更高的级别上起作用,避免了低级别的边缘情况。 然后图灵负责其余的工作。

There are certainly a lot of people who refuse to consider the possibility that JavaScript got anything right. I used to be one of those guys. But now I continue to be amazed by the brilliance that is in there.

当然,有很多人拒绝考虑JavaScript正确实现的可能性。 我曾经是那些家伙之一。 但是现在,我仍然对那里的辉煌感到惊讶。

Brendan Eich, again:

布伦丹·艾希( Brendan Eich )再次:

Doug's point about source beating bytecode is good. My friend Prof. Michael Franz of UC Irvine long ago showed O(n^4) complexity (runaway compute cycles, denial of service) in the Java verifier. JS is strictly more portable and fast enough to lex/parse as minified source.

道格关于源代码跳动字节码的观点是好的。 我的朋友UC Irvine的朋友Michael Franz教授很久以前就在Java验证程序中展示了O(n ^ 4)的复杂性(失控的计算周期,拒绝服务)。 严格来说,JS具有更强的可移植性和足够的速度,足以将lex / parse作为最小源。

Source as "bytecode" also avoids the big stupid Java bytecode mistake: freezing a poorly designed lowered form of Java, then being unable to evolve the high-form source, i.e., the Java programming language for fear of breaking Java bytecode compatibility. This severely messed up the design of inner classes and then generics in Java -- and then Sun broke bytecode compat anyway!

作为“字节码”的源代码还避免了愚蠢的Java字节码错误:冻结设计不佳的降低形式的Java,然后由于担心破坏Java字节码兼容性而无法开发高级格式的源代码,即Java编程语言。 这严重弄乱了内部类和Java泛型的设计-然后Sun还是破坏了字节码的兼容性!

From a YCombinator Thread a while back, Nick Thompson said:

尼克·汤普森( Nick Thompson)从YCombinator Thread回来说:

My admittedly biased view: I spent two years of my life trying to make the JVM communicate gracefully with Javascript - there were plenty of us at Netscape who thought that bytecode was a better foundation for mobile code. But Sun made it very difficult, building their complete bloated software stack from scratch. They didn't want Java to cooperate with anything else, let alone make it embeddable into another piece of software. They wrote their string handling code in an interpreted language rather than taint themselves with C! As far as I can tell, Sun viewed Netscape - Java's only significant customer at the time - as a mere vector for their Windows replacement fantasies. Anybody who actually tried to use Java would just have to suffer.

我的观点是公认的:我花了两年的时间试图使JVM与Javascript优雅地通信-Netscape的许多人认为字节码是移动代码的更好基础。 但是Sun变得非常困难,从头开始构建完整的,肿的软件堆栈。 他们不希望Java与其他任何东西合作,更不用说使其可嵌入到另一软件中了。 他们用一种解释语言编写了字符串处理代码,而不是用C弄脏自己! 据我所知,Sun将Netscape(当时Java唯一的重要客户)视为Windows替代幻想的唯一载体。 任何实际尝试使用Java的人都将遭受痛苦。

Meanwhile Brendan was doing the work of ten engineers and three customer support people, and paying attention to things that mattered to web authors, like mixing JS code into HTML, instant loading, integration with the rest of the browser, and working with other browser vendors to make JS an open standard.

同时,Brendan负责10位工程师和3位客户支持人员的工作,并关注与Web作者相关的事情,例如将JS代码混合到HTML中,即时加载,与其他浏览器集成以及与其他浏览器供应商合作。使JS成为开放标准。

So now JS is the x86 assembler of the web - not as pretty as it might be, but it gets the job done (GWT is the most hilarious case in point). It would be a classic case of worse is better except that Java only looked better from the bottom up. Meanwhile JS turned out to be pretty awesome. Good luck trying to displace it.

因此,现在JS是Web的x86汇编程序-虽然不尽如人意,但可以完成工作(GWT是最搞笑的例子)。 这是一个经典的例子,那就是更好的情况就是更好,只是Java从下至上看起来更好。 同时,JS真是太棒了。 祝你好运,以取代它。

The point is, of course, that no analogy is perfect. Of course JavaScript as a language doesn't look or act like ASM. But as an analogy, it holds up.

重点当然是没有比喻是完美的。 当然,JavaScript作为一种语言并不像ASM那样看起来或不像ASM。 但以此类推,它成立了。

  • JavaScript is ubiquitous.

    JavaScript无处不在。
  • It's fast and getting faster.

    它越来越快。
  • Javascript is as low-level as a web programming language goes.

    Javascript就像Web编程语言一样底层。
  • You can craft it manually or you can target it by compiling from another language.

    您可以手动制作它,也可以通过其他语言进行编译来定位它。

This topic comes up on Hacker News often.

这个话题经常出现在《黑客新闻》上。

  • "The JavaScript we've got now is the assembly language of the client-side. We can't easily change it, but we have to start building better tools on top of it." - jonnycat

    “我们现在获得JavaScript是客户端的汇编语言。我们不能轻易对其进行更改,但是我们必须开始在其之上构建更好的工具。” -强尼猫

Have at it. I enjoy our thoughtful, measured and reasoned discussions, Dear Reader. You guys rock.

吃吧亲爱的读者,我喜欢我们经过深思熟虑,经过认真评估的讨论。 你们真棒。

翻译自: https://www.hanselman.com/blog/javascript-is-assembly-language-for-the-web-part-2-madness-or-just-insanity

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值