JS: World’s Most Misunderstood Has Become Most Popular

Jean Sammet wrote Computer Languages: History and Fundamentals in 1969. It was a survey of 120 programming languages, some in considerable detail. Sammet’s book chronicled languages that were designed before the Structured Programming Revolution and the later development of Object-Orientation. The book’s cover featured a picture of the Tower of Babel. Many of the bricks in the structure of the tower bore the names of programming languages.

Jean Sammet1969年编撰了《计算机语言:历史和基础知识》一书。它综述了120种程序语言,其中不少语言细节翔实。其书按时间为序罗列出了结构化编程革命之前所设计的那些语言及其后面向对象升级版本。书封面以一张巴比伦塔照片作为其显著特征,塔身里许多砖块上还刻着各种程序语言的名字。

This of course refers to Genesis [11:1-9] in which some excellent engineering talent was applied to the task of building a city and a tower with which to unify the world.

这当然指的是创世纪[11:1-9]里所提到的一些杰出工匠被投入到为统一整个世界而建造一座城市和高塔的任务中来的故事。

But the LORD came down to see the city and the tower which the sons of men had built. And the LORD said, “Indeed the people are one and they all have one language, and this is what they begin to do; now nothing that they propose to do will be withheld from them. Come, let Us go down and there confuse their language, that they may not understand one another’s speech.” So the LORD scattered them abroad from there over the face of all the earth, and they ceased building the city. Therefore its name is called Babel, because there the LORD confused the language of all the earth; and from there the LORD scattered them abroad over the face of all the earth.

Sometimes this is read as a warning against hubris. Sometimes this is read as a just-so story explaining why people speak so many languages: The LORD created the I18N Problem to prevent humanity from reaching its potential. But I think its truest interpretation is as a metaphor for programming language design. The principle problem in programming is the management of complexity. If a language does not help us to manage very complex systems in the face of changing requirements, then confusion results, and failure follows.

有将这段话解读成对于傲慢人类的警告;也有将其作为解释人们何以会讲如此众多语言的不过如此的寻常故事:是上帝制造了国际化(I18N)问题以阻止人类达致其极限潜能。而我认为其真实寓意是隐喻了编程语言设计。编程根本问题是复杂性管理。若语言不能有助于面对需求变更时管理非常复杂的系统,则混乱终至、而失败紧随。

Why are there so many programming languages? Beyond the Sammet set, there have been lots of new languages and dialects developed over the past 40 years. We have been programming at a High Level for a very long time. Shouldn’t we have converged on the right way to do it by now? There are obvious efficiencies that would be obtained from the design and adoption of a single, perfect language. We could focus our resources more effectively on training and tool development. Why haven’t we done that?

为何会有如此众多的编程语言呢?在Sammet所收集子之外,过去40年间又已经开发涌现了大量新语言及其变种。我们已经在高层编程很久了。现在我们难道不应该汇聚到正确的编程道路上来么?通过设计、采用单一的一门完美语言,所能获得的效率明显是存在的。我们就能将资源更高效的集中在培训和工具开发上。为何却事与愿违呢?

We have been trying. There have been several attempts to build massive, universal languages. They all failed. As a language design grows, increasing its applicability, it becomes more and more complex. Designers who makes their language too complex will confuse the language, sayeth the LORD.

我们已在上下求索。已有相当多尝试,建造大规模、统一语言的尝试,全都失败了。当语言设计不断发展、不断增广其适用范围时,语言就会变得越来越复杂。 上帝曰:把语言弄得太过复杂的设计者自己都将被语言搞迷糊。

So we see instead a large number of more specialized languages. A specialized language will be very effective for some range of tasks. And that’s good enough. For people who have to accomplish those tasks, having the the right language can be, well, a godsend.

因此,相反我们看到的是大量更为专门化的语言。专门的语言用于某个特定范围内的任务将会非常有效,而且好到不能再好。对于要完成那些任务的人而言,拥有合适的语言可算得上是——简直了——天赐予。

A programming language cobbles a model of computation with some sort of expressive syntax. Most languages will have a set of useful values such as numbers and texts (which most languages, strangely, call strings), and operations that mutate and synthesize values and some form of variation or repetition, and some way of packaging operations into more convenient idioms. The variations that are possible are endless, much like the variations possible in the preparation of a fine meal or a work of music. The art in language design is knowing what to leave out. The features of a good language work together harmoniously. A good language helps us to better understand a problem and to find the best expression of its solution.

编程语言往往会在计算模型中缀入某些类具有表达能力的语法。绝大多数编程语言都会有一整套诸如数字、文本(诡异的是,它们都叫它“ 字符串 ”)等的值、用以改变、合成这些值及其某种形式变体或重复的运算、以及一些将这些运算打包在一起构成更为便捷短语表达的方式。可能的变体无穷无尽、很像准备一顿美味佳肴或创作一首音乐作品一样,各种花样和套路。语言设计的艺术在于懂得如何取舍。好语言特性彼此和谐起效。好语言能有助于我们更好的理解问题并找出其解答的最佳表达。

A good language is composed of a limited set of features. But there is little agreement on which features are best. Programmers can argue endlessly about features and whether they make one language better than another. This does not mean that the features don’t matter. They matter greatly. We just don’t understand yet how they matter.

好语言只能由有限特性构成。然而到底哪些个特性才是最棒的却众说纷纭。程序员们能就这些特性本身及其是否使得一门语言较之另一门为好的问题上争论个不休。这并非是说这些特性无所谓,它们事实上很重要,只不过它们怎样个重要法,我们仍不是很了然。

Language design has more to do with fashion than technology. It may seem strange that fashion is a major factor in the nerdliest of arts, but it is true. A language with radically different syntax, for example, has no hope of finding broad adoption, regardless of the brilliance of its design. This tends to constrain the rate at which languages evolve.

相比技术而言,语言设计更易受时代潮流影响。认为潮流才是这门最为书卷气艺术的主要影响因子,可能会让人觉得不可思议,但事实的确如此。举例说,如果一门语言采用十分激进、完全不同的语法的话,将会没什么希望得到广泛采纳,无论其设计有多么耀眼。而这就很可能会限制语言进化的速度。

Like music and food, a programming language can be a product of its time. The deep problem in language design is not technological, it is psychological. A programming language should equip us with structures that help us to reason more effectively.

如同音乐和美食,编程语言也会是时间的积淀物。语言设计的深层问题不在技术方面,而是在心理方面。编程语言应能提供一些结构装备以便我们能更为有效进行推理。

Programming languages are like cats. It is easier to get a new cat than to get an old cat fixed. Most successful languages are ultimately replaced by upstarts. Remodeled languages rarely match the glory of the original. Fortran was once the king of languages. It has been revised several times over the years, but the modernized dialects experienced a fraction of the prestige of Fortran IV. Similarly, Pascal was a popular structured programming language, but none of the object oriented dialects ever approached Pascal’s glory. Instead, languages tend to be superseded.

造语言像养猫。新养一只远比阉割老猫来得容易。许多很成功的语言最终都被后起之秀所取代。而这些改装的语言罕有原生的风光。FORTRAN曾是王者语言,多年来被数次改版,但这些摩登版所斩获声名尚不及FORTRAN IV的一个零头。同样,Pascal也曾是一门红极一时的结构化编程语言,但其面向对象改进版本却没有一门曾重现其往日荣光。然而,语言终究会换代下去。

Specialized languages are fun to make, which partly explains why there are so many. If a language doesn’t get too big, it can be managed by a single designer. Most languages can be identified with a single designer. Pascal: Wirth. C: Ritchie. C++: Stroustrup. Java: Gosling. C#: Hejlsberg. Rebol: Sassenrath. Python: van Rossum. PHP: Lerdorf. Perl: Wall. Ruby: Matsumoto. Lua: Ierusalimschy. E: Miller. JavaScript: Eich.

专门语言造起来十分有趣,这也部分解释了它们为何会如此之多。一门语言尚未变得过于庞大前,单个设计者即可掌控。绝大多数语言都能归功于某单个的设计者: Pascal => Wirth、C => Ritchie、C++ => Stroustrup、Java => Gosling、C# => Hejlsberg、Rebol => Sassenrath、Python => van Rossum、PHP => Lerdorf、Perl => Wall、Ruby => Matsumoto、Lua => Ierusalimschy、E => Miller、JavaScript => Eich。

Most languages die in obscurity. Only a few are able to build a following beyond a single project or company. And only a very small number of languages become important.

大多数语言糊里糊涂的就死掉了, 其中只有少数语言在其所发轫的单个项目或公司之后仍能后继有为,而这当中又只有非常小数目的语言真正变得举足轻重。

There are two ways that a language becomes important. The first is as a source or proving ground for important ideas. This includes languages like Smalltalk and Scheme. These languages are not widely used, but are generally recognized as brilliant, but out of fashion. They have a powerful influence on language designers.

一门语言要变得重要有两种途径:一是作为源头或试验场。比如Smalltalk与Scheme就在此列,它们并未被广泛使用,但被公认为是光芒四射的语言,当然也不算时髦。它们对语言一众设计者们有着强大的影响。

The second way that a language becomes important is by becoming popular.There are many things that a programmer must consider when selecting a program language unless that programmer is writing for web browsers where the only choice currently is JavaScript.

二是通过变得流行因而重要起来。程序员挑选编程语言时有很多事项都必须要考虑到,除非他是在为Web浏览器编程,此处当下只有唯一选择:JavaScript。

JavaScript is an astonishing language, in the very worst sense. Its astonishing nature led to a very bad reputation. JavaScript is also coupled with The DOM, a horrendous API. There is a lot of confusion about where JavaScript ends and the DOM begins. There is lots of chatter about improving JavaScript, but that by itself would do little to improve the lives of web developers. The language is burdened with too many features, including many that interact badly or were poorly designed. It is a language that has, as Emperor Joseph would say, too many notes.

JavaScript是一门令人咂舌(非常负面意义上)的语言,因此而带来了非常坏的名声。而且JavaScript还总和DOM这一可怕的API搅在一起。究竟JavaScript是在哪里结束而DOM又是在哪里开始的,云山雾罩。就改进JavaScript多少次甚熙尘上,但仅改进它自己,对于改善Web开发者境况实难有所作为。该语言背负了太多的特性,包括大量交互性差、没怎么好好设计的特性。正像Emperor Joseph所说的,它就是这样一门特性过多、乱七八糟的语言。

So how did a language with such obvious deficiencies become the Sole Programming Language of the Web? Brendan Eich convinced his pointy-haired boss at Netscape that the Navigator browser should have its own scripting language, and that only a new language would do, a new language designed and implemented in big hurry, and that no existing language should be considered for that role. The Internet Explorer team at Microsoft wanted to capture Netscape’s market share, so they carefully reverse engineered Netscape’s language, huge hairy warts and all. The other browser makers followed Microsoft’s lead. There is no standard that says that a web browser must implement JavaScript; JavaScript is the only language implemented in all popular web browsers. There was no careful review of the language or its problem domain. There was no review of its suitability or the soundness of its design. It was slapped together at Netscape, and then copied elsewhere. Given the process that created JavaScript and made it a de facto standard, we deserve something far worse.

那么,这样一门有着诸多不足的语言何以能变成Web编程语言独一份的呢?Brendan Eich说服了他在Netscape时的秃头老板,Navigator浏览器应有属于其自身的脚本语言,且只能是新语言、一门极度赶工设计和实现的新语言才行,而无任一现存语言可堪考虑用于此途。微软的IE团队想跟Netscape抢夺市场份额,所以他们仔仔细细逆向工程了Netscape的语言,连毛带包、不分良莠一股脑照抄。其他浏览器制造商萧规曹随微软。没有任一标准说Web浏览器必须要实现JavaScript,但JavaScript是唯一被所有流行Web浏览器实现了的语言。没人花心思仔细审查这门语言及其问题所在,也没人留意其设计是否合适或合理。它先是在Netscape被随意与浏览器拍到了一起,随后又被拷贝到其他各处。若按这样的过程创建JavaScript并将其做成事实标准,我们理应得到更糟的结果才对。

But despite JavaScript’s astonishing shortcomings, deep down, in its core, it got something very right. When you peel away the cruft, there is an expressive and powerful programming language there. That language is being used well in many Ajax libraries to manage and augment the DOM, producing an application platform for interactive applications delivered as web pages. Ajax has become popular because JavaScript works. It works surprisingly well.

不过抛开JavaScript这些令人咂舌的缺点,深入其核心,其中有一些很正确的东西。当你剥离它这些赘疣,那儿便会留下一门富于表现力的强大的编程语言。这门语言被很多Ajax程序库广泛用于管理和完善DOM、创建出以网页形式递交、用于交互应用的应用平台。因JavaScript好用,不可思议的好用,Ajax已变得流行起来 。

JavaScript was the world’s most misunderstood programming language. Its obvious defects, its unfashionable programming model, intentional mispositioning at its introduction, and its ridiculous name caused it to be rejected as unworthy by most knowledgeable programmers. But Ajax gave JavaScript a second chance.

JavaScript是这世上最被误解的编程语言。它明显的缺陷、不流行的编程模型、错误的初始定位、再加那滑稽的名字,凡此种种导致了大量见多识广程序员的抵制,认为不值一用。但Ajax给了JavaScript再次生命。

Because JavaScript is the language of the web browser, and because the web browser has become the dominant application delivery system, and because JavaScript isn’t too bad, JavaScript has become the World’s Most Popular Programming Language. Its popularity is growing. It is now being embedded in other applications and contexts. JavaScript has become important.

因JavaScript是Web浏览器语言,而Web浏览器成为占统治地位的应用交付系统,且JavaScript也并非不可救药,JavaScript已渐渐变成世界上最流行的编程语言。其流行度与日俱增,它现在已被嵌入到其他应用和场景当中。JavaScript已愈发重要。

It is better to be lucky than smart.

运气有时要比聪明的头脑还重要。

Leave a comment

Your email address will not be published. Required fields are marked *