【转(中英文)】通天塔导游(Tour de Babel):各种编程语言的优缺点

这是一篇吐槽文,部分观点大家看看就好。另:这篇文章成文似乎也比较早,所以有些预测大家也可以看看是否准确。

目录

【译注】:圣经记载:在远古的时候,人类都使用一种语言,全世界的人决定一起造一座通天的塔,就是巴别塔,后来被上帝知道了,上帝就让人们使用不同的语言,这个塔就没能造起来。 巴别塔不建自毁,与其说上帝的分化将人类的语言复杂化,不如说是人类自身心灵和谐不再的分崩离析。之所以后来有了翻译,不仅是为了加强人类之间的交流,更寄达了一种愿望,希望能以此消除人际的隔阂,获求来自心灵的和谐及慰藉。真正的译者,把握血脉,抚平创痕,通传天籁,开启心门。

这是我写的旋风式的编程语言简介 —— 我本来为亚马逊开发者杂志本月的期刊写的,但是发现我写的东西没法见人。

This is my whirlwind languages tour — the one I was going to write for the Amazon Developers Journal this month, but couldn't find a way to do it that was... presentable.

首先,我偶尔一不小心口出脏话,或者对上帝不恭的话,所以在很官方很正式的亚马逊上发表是不合适的; 所以我就把它塞到我的博客里了,我的博客反正没人看的。除了你以外。是的,只有你会看,你好啊。

For one thing, I lapse occasionally into coarseness and profanity here, so it wasn't appropriate for an official-ish Amazon publication. Instead, I'm stuffing it into my blog, which nobody reads. Except for you. Yep, just you. Hiya.

其次,这是一项进行中的工程,现在只是东打一耙西搞一下,还没有精加工过的。又一个把它写到博客里的很大的理由。不需要很好,或很完整。就是我今天想说的一些话。请随便!

For another, it's really a work in progress, just a few snippets here and there, not polished at all. Another great reason to make it a blog entry. Doesn't have to be good, or complete. It's just what I've got today. Enjoy!

我的旋风式简介会讲 C、C++、Lisp、Java、Perl (我们在亚马逊用到的所有语言)、Ruby (我就是喜欢) 和 Python,把 Python 加进来是因为 —— 好吧,你看了就知道了,现在我可不说。

My whirlwind tour will cover C, C++, Lisp, Java, Perl, (all languages we use at Amazon), Ruby (which I just plain like), and Python, which is in there because — well, no sense getting ahead of ourselves, now.

C

你必须懂 C。为啥? 因为出于所有现实的理由,这个世界上你过去,现在,将来会用到的每一台计算机都是一台冯·诺依曼机器,而 C 是一种轻量级的,很有表达力的语法,能很好的展现冯·诺依曼机器的能力。

You just have to know C. Why? Because for all practical purposes, every computer in the world you'll ever use is a von Neumann machine, and C is a lightweight, expressive syntax for the von Neumann machine's capabilities.

冯·诺依曼架构就是你每天都用的计算机的架构的标准:一个 CPU,内存,硬盘,一条总线。多核计算机并没有带来本质上的变化。冯·诺依曼机是一个很方便,很便宜,上世纪五十年代的实现图灵机的技术,图灵机是执行计算的最知名的抽象模型。

The von Neumann architecture is the standard computer architecture you use every day: a CPU, RAM, a disk, a bus. Multi-CPU doesn't really change it that much. The von Neumann machine is a convenient, cost-effective, 1950s realization of a Turing Machine, which is a famous abstract model for performing computations.

世上还有其他的计算的机器。比如,Lisp 机器,是上世纪 50 年代对 Lisp 计算模型的实现。Lisp 模型是基于 lambda 代数的一种计算语言表示法,后者是与图灵机同构的一种模型。不像图灵机,lambda 代数能被人类读和写。但是这二者是同等能力的。它们同样精确的表示了计算机能干什么。

There are other kinds of machines too. For instance, there are Lisp Machines, which are convenient 1950s realizations of Lisp, a programming language notation based on the lambda calculus, which is another model for performing computations. Unlike Turing machines, the lambda calculus can be read and written by humans. But the two models are equivalent in power. They both model precisely what computers are capable of.

Lisp 机现在不是很流行了,除了在跳蚤市场里。从谁更受欢迎来说,冯·诺依曼机器赢了。还有一些其他的计算机,比如神经网络计算机或元胞自动机,但是这些都不够大众化,至少现在是这样的。

Lisp Machines aren't very common though, except at garage sales. von Neumann machines won the popularity race. There are various other kinds of computers, such as convenient realizations of neural networks or cellular automata, but they're nowhere as popular either, at least not yet.

所以你必须知道 C。

So you have to know C.

还有一个你必须知道 C 的原因是,Unix 是用 C 写的。巧的是,Windows 也是。基本上所有的其他操作系统都是用 C 写的。因为这些操作系统都是冯·诺依曼机的操作系统,你还能用别的吗? 任何跟 C 很不一样的东西都会跟硬件的实际能力相差太远而导致无法满足性能上的需要,至少对一个操作系统来说是这样—至少在上个世纪是这样,碰巧这些系统都是上个世纪的。

You also have to know C because it's the language that Unix is written in, and happens also to be the language that Windows and virtually all other operating systems are written in, because they're OSes for von Neumann machines, so what else would you use? Anything significantly different from C is going to be too far removed from the actual capabilities of the hardware to perform well enough, at least for an OS — at least in the last century, which is when they were all written.

你还应该知道 Lisp。你不必用它来干实际工作,虽然它在很多 GNU 的软件里都会很用得着。尤其是,你应该学会 Scheme,Lisp 的一种小巧化的,纯洁的方言。GNU 的版本叫 Guile。

You should also know Lisp. You don't have to use it for real work, although it comes in quite handy for lots of GNU applications. In particular, you should learn Scheme, which is a small, pure dialect of Lisp. The GNU version is called Guile.

他们在麻省理工和加州伯克利教新学生一到两个学期的 Scheme,这些学生都对他们为啥要学这么奇怪的语言抓破脑袋。实话实说,作为第一门学习的语言,这是一个很烂的选择,第二门也是很烂。你应该学会它,最终,但不是作为第一门或第二门语言。

They teach Scheme at MIT and Berkeley to new students for a semester or two, and the students have absolutely no clue as to why they're learning this weird language. It's a lousy first language, to be honest, and probably a lousy second one too. You should learn it, eventually, and not as your first or second language.

这是很难的哦。这是很大的一步。学会怎么用 Lisp 写出像 C 语言的程序是不够的,那没有意义。C 和 Lisp 一个就像红外线,一个就像紫外线,它们分布在光谱的最两端。它俩一个牛逼的地方刚好是另一个傻逼了的地方。

It's hard, though. It's a big jump. It's not sufficient to learn how to write C-like programs in Lisp. That's pointless. C and Lisp stand at opposite ends of the spectrum; they're each great at what the other one sucks at.

如果说,C 是最靠近计算机是如何工作的语言模型,Lisp 就是最能反映计算(注意,这里没有了“机”字,计算机和计算是很不同的!译者注)是如何工作的模型。你不需要懂很多 Lisp,真的。紧咬 Scheme 就哦了,因为它是最简单最干净的。其他的 Lisp 已经发展成了很大,很复杂(很好很强大? 译者:-)的编程环境,就像 C++ 和 Java,要有很多库啊,工具啊等等之类。那些,你不需要知道。但是你应该能用 Scheme 写程序。如果你能够做出 The Little Schemer 和 The Seasoned Schemer 这两本书里的所有习题,你懂得就够多了,我认为。

If C is the closest language to modeling how computers work, Lisp is the closest to modeling how computation works. You don't need to know a lot of Lisp, really. Stick with Scheme, since it's the simplest and cleanest. Other Lisps have grown into big, complex programming environments, just like C++ and Java have, with libraries and tools and stuff. That, you don't need to know. But you should be able to write programs in Scheme. If you can make your way through all the exercises in The Little Schemer and The Seasoned Schemer, you'll know enough, I think.

但是对于你天天要做的编程工作,你应该基于以下条款选择你的语言:库,文档,工具支持,操作系统集成,资源,和一堆其他的东西。这些条款跟计算机如何工作关系很小,但是跟人类如何工作关系甚大。

But you choose a language for day-to-day programming based on its libraries, documentation, tools support, OS integration, resources, and a host of other things that have very little to do with how computers work, and a whole lot to do with how people work.

人们还在用很直白的 C 语言写东西。很多东西。你应该懂 C!

People still write stuff in straight C. Lots of stuff. You should know it!

C++

C++ 是地球上最蠢的语言,即使是从蠢这个字的真正意义上出发。C++ 很无厘头。它不知道自己是什么东西。它没有自省(introspective,面向对象里的一个概念,译者注)。C 也没有,但是 C 不是“面向对象”的,而面向对象很大程度上是关于要让你的程序知道它自己。对象就像演员。所以面向对象语言应该有运行时的自省机制,知道自己是个什么类的对象。C++ 不是这样的,真的,你不会那样用它。

C++ is the dumbest language on earth, in the very real sense of being the least sentient. It doesn't know about itself. It is not introspective. Neither is C, but C isn't "Object-Oriented", and object orientation is in no small measure about making your programs know about themselves. Objects are actors. So OO languages need to have runtime reflection and typing. C++ doesn't, not really, not that you'd ever use.

关于 C:写一个 C 的编译器是那么的简单,以至于你可以用 C 写一个关于 C 的工具,用起来就像是有内省机制。而 C++ 呢,基本上是不可解析的,所以如果你想写一个很牛逼的工具用来 —— 比如,告诉你你的虚函数的原型,或者帮你重构你的代码,你将不得不依赖别人的工具集,因为你自己在除非脑子进屎的情况下是根本不会去写一个 C++ 的解析器的。而市面上所有的 C++ 的解析器都很傻逼。

As for C: it's so easy to write a C compiler that you can build tools on top of C that act like introspection. C++, on the other hand, is essentially un-parseable, so if you want to write smart tools that can, for example, tell you the signatures of your virtual functions, or refactor your code for you, you're stuck using someone else's toolset, since you sure as heck aren't gonna parse it. And all the toolsets for parsing C++ out there just plain suck.

C++很蠢,你不能用蠢语言创造一个好系统。语言决定世界,蠢语言决定蠢世界。

C++ is dumb, and you can't write smart systems in a dumb language. Languages shape the world. Dumb languages make for dumb worlds.

所有的计算都基于抽象。你用低级的东西创造出高级的东西。但是你不能用分子创造出一个城市。尝试使用太低级别的抽象只会给你带来麻烦。

All of computing is based on abstractions. You build higher-level things on lower-level ones. You don't try to build a city out of molecules. Trying to use too low-level an abstraction gets you into trouble.

我们就惹上麻烦了 (是指亚马逊的员工,还是所有 C++ 的程序员? 我也不知道,译者注)。

We are in trouble.

理智的情况下,你用 C 写的最大的东东就是一个操作系统。而操作系统其实不是很大的,真的。它们看起来很大,但那是因为它们有很多应用软件,操作系统本身的内核是蛮小的。

The biggest thing you can reasonably write in C is an operating system, and they're not very big, not really. They look big because of all their apps, but kernels are small.

你用 C++ 能写的最大的东东是……也是操作系统。好吧,或许稍微再大点儿。让我们说,再大三倍吧。或者 10 倍吧。但是操作系统内核最多也就,那啥,一百万行代码? 所以我说你能用 C++ 写的最大的系统大概也就是一千万行代码吧,再大的话就开始不行了,这玩意儿你没法控制了,就像恐怖片里的……

The biggest thing you can write in C++ is... also an operating system. Well, maybe a little bigger. Let's say three times bigger. Or even ten times. But operating system kernels are at most, what, maybe a million lines of code? So I'd argue the biggest system you can reasonably write in C++ is maybe 10 million lines, and then it starts to break down and become this emergent thing that you have no hope of controlling, like the plant in Little Shop of Horrors. Feeeeeed meeeeeee...

我说的一千万行是指如果你那时候还能让你的系统编译通过的话。

If you can get it to compile by then, that is.

我们(在亚马逊,译者注)有五千万行 C++ 代码。不,现在还要更多了。我已经不知道有多少行了。上个圣诞节是五千万行,那是九个月前,而它以每季度八百万行的规模增长。增长率本身也增长,妈呀。

We have 50 million lines of C++ code. No, it's more than that now. I don't know what it is anymore. It was 50 million last Christmas, nine months ago, and was expanding at 8 million lines a quarter. The expansion rate was increasing as well. Ouch.

我们想在这个系统里干点啥好像要一万年。一个亚马逊工程师有一次这样描述我们的代码库:“一座很大的屎山,你见过的最大的山,每次你想修正一个 bug,你的工作就是爬到屎山的正中心去。”

Stuff takes forever to do around here. An Amazon engineer once described our code base as "a huge mountain of poop, the biggest mountain you've ever seen, and your job is to crawl into the very center of it, every time you need to fix something."

伙计们,那哥们可是在四年前说的这话。他现在已经到更环保绿色的牧场上去了。真是太可惜了,他可是个实实在在的高手啊。

That was four years ago, folks. That engineer has moved on to greener pastures. Too bad; he was really good.

这都是 C++ 的错。别跟我争论。就是的。我们用的是世上最蠢的语言。这简直有点老板级的蠢,你说呢? (译者注,meta 在计算机术语里通常表示更高一个层次,比如,meta-language,比普通的 language 高一个层次,意思是关于语言的语言。哲学里应该会经常用到这个词。我不懂哲学,但是我觉得老板们总是比我们高一级,所以 meta-dump 我就翻译成老板级的蠢喽。:-)

It's all C++'s fault. Don't argue. It is. We're using the dumbest language in the world. That's kind of meta-dumb, don't you think?

说了以上这些难听的话,话得说回来了。用 C++ 写出漂亮的代码显然是可以的,我的意思是说,这样的代码应该大部分还是 C,偶尔很有品味的,很有节制的用一点C++。但是这种代码几乎从来不会被写出来。C++ 是个很好玩的游乐场,而如果你把它玩儿得门儿清的话你会觉得自己特牛,所以你总是被诱惑把你知道的所有的东西都用上。但是那是很难做好的,因为从一开始这个语言就太狗屎了,最终,你会弄得一塌糊涂,即使你很能干。

With that said, it is obviously possible to write nice C++ code, by which I mean, code that's mostly C, with some C++ features mixed in tastefully and minimally. But it almost never happens. C++ is a vast playground, and makes you feel smart when you know all of it, so you're always tempted to use all of it. But that's really, really hard to do well, because it's such a crap language to begin with. In the end, you just make a mess, even if you're good.

我知道,我说的都是异端邪说,该被钉到十字架上的。随便吧。我在大学里的时候老喜欢 C++ 了,因为我那时候就只知道这一门语言。当我听到我的语言教授,Craig Chambers,绝对的厌憎 C++,我想:“为啥呢? 我觉得它挺好的啊”。而当我听到 STL (标准模板库)的发明者被采访时说他恨 OOP (面向对象编程)时,我更是认为他肯定是磕药了。怎么会有人恨 OOP 呢,而这个人竟然还是 STL 的发明者?

I know, this is Heresy, with a capital-'H'. Whatever. I loved C++ in college, because it's all I knew. When I heard that my languages prof, Craig Chambers, absolutely detested C++, I thought: "Why? I like it just fine." And when I heard that the inventor of STL was on record as saying he hated OOP, I thought he was cracked. How could anyone hate OOP, especially the inventor of STL?

亲不敬,熟生厌(语出圣经,译者注)。说的是在大多数情况下,跟一件事物熟悉了之后你就失去对它的膜拜尊敬了; 在计算机语言里情况不是这样的。光对一门语言熟悉不会导致你看轻这门语言。你必须成为另一门更优秀的语言的专家(才能让你明白原来那门语言有多么多的问题)。

Familiarity breeds contempt in most cases, but not with computer languages. You have to become an expert with a better language before you can start to have contempt for the one you're most familiar with.

所以如果你不喜欢我针对 C++ 大放厥词,请你去学另一门语言并成为一个专家(我推荐 Lisp),只有那时你才有足够的武器与我争论。然而,那时你将不会跟我争了。你上了我的当了。你也会跟我一样变得不喜欢 C++ 了,你或许会觉得我这个人很恶心,把你骗得不喜欢自己曾经的最爱了。所以或许你应该把我说的一切都忘了。C++挺好的其实,真的。它就是很棒棒(译者注,作者在这里用了 ducky,这是一个女性喜欢用的夸某物好的词,近来也为玻璃们喜爱)。忘了我说的话。C++ 不错的。

So if you don't like what I'm saying about about C++, go become an expert at a better language (I recommend Lisp), and then you'll be armed to disagree with me. You won't, though. I'll have tricked you. You won't like C++ anymore, and you might be irked that I tricked you into disliking your ex-favorite language. So maybe you'd better just forget about all this. C++ is great. Really. It's just ducky. Forget what I said about it. It's fine.

Lisp

(我打赌这一节会让你觉得惊讶,即使你已经关注我的博客有一阵了[译者注,作者也可能是说,即使你成为亚马逊的员工有一阵了])

(I'm betting this next section will astonish you, even if you've been here a while.)

亚马逊创业之初,我们有很多明星级的工程师。我不认识他们所有人,但是我认识几个。

When Amazon got its start, we had brilliant engineers. I didn't know all of them, but I knew some of them.

比如?Shel Kaphan, 大拿。Greg Linden, 大拿。Eric Benson。即使在他加入亚马逊之前就已经有自己响亮的名气了。也是大拿。

Examples? Shel Kaphan. Brilliant. Greg Linden. Brilliant. Eric Benson. Independently famous in his own right, before he ever even came to Amazon. Also brilliant.

他们写了 Obidos 服务器。是 Obidos 让亚马逊成功的。只是后来那些生产大便很拿手的工程师,网页开发者,搞前端的人 —— 这些人因为生产大便很拿手而总是能让经理们满意 —— 只是在后来这些人把 Obidos 搞糟了。(他们的大便)把整条河都堵了,打个比方说的话。但是 Obidos 是亚马逊最初的成功的一块关键的基石。

They wrote the Obidos webserver. Obidos made Amazon successful. It was only later that poop-making engineers and web devs, frontend folks mostly — schedule-driven people who could make their managers happy by delivering crap fast — it was only later that these people made Obidos bad. Clogged the river, so to speak. But Obidos was a key cornerstone of Amazon's initial success.

这些最早的牛人们在亚马逊神圣的代码库里只允许两种语言:C 和 Lisp。

The original brilliant guys and gals here only allowed two languages in Amazon's hallowed source repository: C and Lisp.

你自己去想吧。

Go figure.

当然,他们所有人都使用 Emacs。靠,Eric Benson 是 XEmacs 的作者之一。这个世界上所有伟大的工程师都在用 Emacs[注1]。那种世界因你而不同级别的伟大。不是坐在你旁边的格子里的那哥们那种伟大。也不是 Fred,走廊尽头那哥们。我说的是我们这个行业里最伟大的软件开发者,那些能改变这个工业的面貌的人。像 James Gosling 们(Java 语言设计者),Donald Knuth 们(这个人没有听说过的话赶紧改行吧,别搞计算机了),Paul Graham 们[注2],Jamie Zawinski 们,Eric Benson 们。真正的工程师用 Emacs。你必须很有点聪明才能把 Emacs 用好,而如果你能成为一个 Emacs 大师的话它会给你难以置信的牛力。有机会的话你应该站到 Paul Nordstrom 的肩后看看他是怎么工作的,如果你不相信我的话。对那些一辈子都在用烂 Visual Studio 之类的集成开发环境的人来说,一定会大开眼界的。

They all used Emacs, of course. Hell, Eric Benson was one of the authors of XEmacs1. All of the greatest engineers in the world use Emacs. The world-changer types. Not the great gal in the cube next to you. Not Fred, the amazing guy down the hall. I'm talking about the greatest software developers of our profession, the ones who changed the face of the industry. The James Goslings, the Donald Knuths, the Paul Grahams2, the Jamie Zawinskis, the Eric Bensons. Real engineers use Emacs. You have to be way smart to use it well, and it makes you incredibly powerful if you can master it. Go look over Paul Nordstrom's shoulder while he works sometime, if you don't believe me. It's a real eye-opener for someone who's used Visual Blub .NET-like IDEs their whole career.

Emacs 是那种你可以用 100 年的编辑器。

Emacs is the 100-year editor.

Shel, Eric, Greg,和其他像他们那样的人,我没有足够幸运能跟他们直接一起工作:他们禁止在这里使用 C++,他们禁止使用 Perl(或者 Java,为完整起见)。他们是明白人。

Shel, Eric, Greg, and others like them that I wasn't fortunate enough to work with directly: they didn't allow C++ here, and they didn't allow Perl. (Or Java, for that matter). They knew better.

现在我们都在用C++,Java 和 Perl 了,所有的代码都用这些语言。我们的前辈们已经到更环保的牧场上去了 (指没有大便的牧场,译者注)。

Now C++, Java and Perl are all we write in. The elders have moved on to greener pastures too.

Shel 用 C 写了 Mailman,客服部的人把它用 Lisp 封装了一下。Emacs-Lisp。你不需要知道 Mailman 是什么东西。除非你是个 Amazon 的老员工,或许不是搞技术的,而且你曾经不得不让客户哈皮 (只有在这种情况下你才需要知道 Mailman,译者注)。不是间接的,因为你用 C++ 写的一个狗屎功能跑不起来了,让客户很生气,于是你不得不去搞定它以恢复客户的哈皮度。不,我是说直接的,意思是,你必须跟他们聊。我们可爱的,不识字的,呱呱其谈的,心地善良的,充满希望的,困惑的,能帮点小忙的,愤怒的,哈皮的客户们,真正的客户们,那些从咱们这里买东西的人,我们的客户们。(如果你必须跟他们打交道的话,)那你就会知道 Mailman 这个东西。

Shel wrote Mailman in C, and Customer Service wrapped it in Lisp. Emacs-Lisp. You don't know what Mailman is. Not unless you're a longtime Amazon employee, probably non-technical, and you've had to make our customers happy. Not indirectly, because some bullshit feature you wrote broke (because it was in C++) and pissed off our customers, so you had to go and fix it to restore happiness. No, I mean directly; i.e., you had to talk to them. Our lovely, illiterate, eloquent, well-meaning, hopeful, confused, helpful, angry, happy customers, the real ones, the ones buying stuff from us, our customers. Then you know Mailman.

Mailman 是客服部的客户电子邮件处理软件,我们用了它有…四,五年? 反正是很长时间。它是用 Emacs 写的,所有人都爱死它了。

Mailman was the Customer Service customer-email processing application for ... four, five years? A long time, anyway. It was written in Emacs. Everyone loved it.

人们现在还很爱它。直到今天,我依旧不得不听我们一些非技术员工跟我长篇大论的叨叨他们是多么的怀念 Mailman。我可绝不是满嘴喷粪。上个圣诞节我参加了一个 Amazon 的派对,一个我不知道自己怎么会被邀请的派对,里面全是些西装笔挺的商务人士,谁都长得比我帅,比我光鲜。以及一些我在公司里曾经打过交道的人(这句不知道怎么译)。四个美女认出了我是在客服部里干的,把我包围了,跟我说了十五分钟她们是多么的怀念 Mailman 和 Emacs,而现在的亚马逊(我们用 JSP 花了好多年准备换掉 Mailman 的那一套软件)是怎么的不能满足她们,让她们觉得跟以前一样爽。

People still love it. To this very day, I still have to listen to long stories from our non-technical folks about how much they miss Mailman. I'm not shitting you. Last Christmas I was at an Amazon party, some party I have no idea how I got invited to, filled with business people, all of them much prettier and more charming than me and the folks I work with here in the Furnace, the Boiler Room of Amazon. Four young women found out I was in Customer Service, cornered me, and talked for fifteen minutes about how much they missed Mailman and Emacs, and how Arizona (the JSP replacement we'd spent years developing) still just wasn't doing it for them.

这一切都太梦幻了,我觉得她们可能是喝多了。

It was truly surreal. I think they may have spiked the eggnog.

Shel 是个天才。Emacs 是天才。连非技术人员都爱 Emacs。我现在就是在 Emacs 里打这些文字。我绝不情愿在任何其他地方打字。这不只是关于让你的效率得到飞跃,通过那些地球上其他地方找不到的快捷键和文本编辑功能。我每分钟打一百三到一百四十个英文单词,在 Emacs 里,当我在写没有格式要求的文本的时候。我测过这个时间速度。自己写了一个测打字速度的 Emacs 应用。但我想跟你说的不只是这个。

Shel's a genius. Emacs is a genius. Even non-technical people love Emacs. I'm typing in Emacs right now. I'd never voluntarily type anywhere else. It's more than just a productivity boost from having great typing shortcuts and text-editing features found nowhere else on the planet. I type 130 to 140 WPM, error-free, in Emacs, when I'm doing free-form text. I've timed it, with a typing-test Emacs application I wrote. But it's more than that.

Emacs 有的是一种你叫不出名字来的品质。

Emacs has the Quality Without a Name.

我们现在不用 Mailman 了。那是因为我们有一种叫得出名字的品质 —— 就是,烂。我们很烂。我们(当时)找不到 Emacs-Lisp 足够牛的人把 Mailman 继续搞下去。今天这应该不难了; 亚马逊现在到处都是 Emacs Lisp 的黑客。但是在那时候,客服部的人没法从别人那里得到帮助。于是他们就用他们当时手头有的资源去搞这件事。他们当时没有足够多的 Emacs-Lisp 的人。有一段时间,他们甚至找来 Bob Glickstein 当合同工,那个给 O’Reilly 写了那本 Gnu Emacs 扩展的书的家伙,坐在一个小办公室里给 Emacs 写 Mailman 的扩展。

We retired Mailman. That's because we have the Quality With a Name — namely, Suckiness. We suck. We couldn't find anyone who was good enough at Emacs-Lisp to make it work. Nowadays it would be easy; Amazon's filled up with Emacs Lisp hackers, but back then, CS Apps couldn't get the time of day from anyone, so they did what they could with what they had, and there weren't enough Emacs-Lisp folks. For a while, they even had Bob Glickstein on contract, the guy who wrote the O'Reilly "giraffe" book Writing Gnu Emacs Extensions, sitting there writing Gnu Emacs Extensions for Mailman in this little office in the Securities building.

客服应用部是 Amazon 的第一个两块比萨饼的团队(代表团队人数的增加,编者注)。这个团队是完全自立的。不管是那时还是现在。没人跟他们说话,没人帮他们。没有枪,没有炮,他们自己造。他们没有网页工程师,没有支持工程师。屁也没有。有的只是一堆骨灰级的工程师和一个能带新人的文化。这就是他们需要的一切了。

CS Apps was Amazon's first 2-pizza team, you know. They're completely autonomous — then and now. Nobody talks to them, nobody helps them, they build everything themselves. They don't have web devs, they don't have support engineers, they don't have squat, except for rock-solid engineers and a mentoring culture. And that's all they've ever needed.

但他们最终不得不让 Mailman 光荣退休。妈哎。而我呢今天还听到人们说他们是多么的怀念它。甚至在派对上。

But they had to retire Mailman. Alas. Alackaday. And I still get to hear about how much people miss it. At parties, even.

我想今天按人头比例来说,客服部仍然拥有比亚马逊任何其他团队更多的 Lisp 黑客。可能他们用到 Lisp 的机会不多了,但是 Eric Raymond 说过,即使你很少用 Lisp 写程序,学习 Lisp 会是意义深远的一个经历,能让你下辈子都成为一个更好的工程师。

I think there may still be more Lisp hackers, per capita, in CS Apps than in any other group at Amazon. Not that they get to use it much, but as Eric Raymond said, even if you don't program in it much, learning Lisp will be a profound experience that will make you a better engineer for the rest of your life.

卡尔,宗教现在已经不是大众的精神鸦片了。现在鸦片是集成开发环境了。(卡尔·马克思。这个人不知道的话应该打屁屁)。

Religion isn't the opiate of the masses anymore, Karl. IDEs are.

Java

Java 是过去的 10 年中计算行业里发生过的最好的同时也是最坏的事。

Java is simultaneously the best and the worst thing that has happened to computing in the past 10 years.

一方面,Java 把你从 C++ 编程的很多枯燥易错的细节中解救出来了。没有数组越界了,没有 core dump 了。抛出来的异常能让你精确定位到出错的那一行代码,而且 99% 的时候都是正确的那一行出错了的代码。对象们在需要的时候能智能地把它们自己打印出来。等等等等。

On the one hand, Java frees you up from many mundane and error-prone details of C++ coding. No more bounds errors, no more core dumps. Exceptions thrown point you to the exact line of code that erred, and are right 99% of the time. Objects print themselves intelligently on demand. Etc., etc.

另一方面,除了是一种语言,一个虚拟机,一个巨无霸的类库,一个安全模型,一个可移植的字节码格式,Java 还是一个宗教。邪教。所以你不能太相信对它太虔诚的人。想要招一个好的 Java 工程师是一项很有技术挑战的活。

On the other hand, in addition to being a language, a virtual machine, a huge set of class libraries, a security model, and a portable bytecode format, Java is a religion. So you can't trust anyone who loves it too much. It's a tricky business to hire good Java programmers.

但是总的来说,Java 是软件工程史上的一大进步。

But Java really has been a big step forward for software engineering in general.

从 C++ 到 Java 不只是语法上的改变。这是一种需要一段时间去好好体会的一种震撼性的世界观的转变。这有点像突然你被配了一个执行助理。你知道老总们为什么总是好像有时间去开会,总是知道公司现在运行的情况,总是写出很酷酷的文档吗? 老总们常常忘记其实他们不是一个人在战斗,他们都是两个全职的人,他们和他们的执行助理们。有一个执行助理把你从琐事中解救出来让你有时间去思考那些真的需要你去解决的问题; 没有的话你将不得不花一半的时间在那些无聊的世俗的事情上。切换到 Java 编程语言就把你变成了两个程序员 —— 一个处理那些你不需要关心的东西,另一个可以集中精力在问题本身上。这是一个很震人的改变,一个你应该很快就能习惯能喜欢上的改变。

Going from C++ to Java isn't just changing syntax. It's a shocking paradigm shift that takes a while to sink in. It's like suddenly getting your own Executive Assistant. You know how VPs always seem to have all this time to be in meetings, and know how the company's running, and write cool documents, and stuff like that? VPs tend to forget that they're actually TWO full-time people: their self and their EA. Having an EA frees you up to think about the problems you need to solve; not having one forces you to spend half your time on mundane tasks. Switching to Java turns you into two programmers — one taking care of all this stuff that you no longer have to think much about, and another one focused on the problem domain. It's a staggering difference, and one you can get used to in a real hurry.

就像 Jamie Zawinski (Netscape 牛人,开发 Mozilla 浏览器,好像学历是高中毕业?)在他著名的“Java 真烂(java sucks)”那篇文章里说的:“先说那些好东西:Java 没有 free() 函数。我必须一开始就承认,其他的东西都没什么了不起。(没有 free)是能让我原谅其他所有东西的特性,不管其他东西有多烂。讲完这一点后,我的文章里其他一切几乎都完全没有重要性了。”

As Jamie Zawinski said in his famous "java sucks" article: "First the good stuff: Java doesn't have free(). I have to admit right off that, after that, all else is gravy. That one point makes me able to forgive just about anything else, no matter how egregious. Given this one point, everything else in this document fades nearly into insignificance."

Jamie 的文章写在 1997 年,按 Java 年来算的话是很早以前了,跟他写这篇文章时比,Java 已经有很大的改善; 一些他抱怨的东西甚至已经被 fix 了。

Jamie's article was written in 1997, which in Java years is a long time ago, and Java has improved a lot since he wrote it; some of the things he complains about are even fixed now.

但是大多数还是没有被 fix。Java 作为一门语言还是有点烂。但就如 Jamie 指出的,Java“是今天为止最好的语言。我的意思是说,它是今天市面上那些烂得底儿掉地一堆语言比起来有那么一点能被我接受。”

Most of them aren't. Java does still kind of suck, as a language. But as Jamie points out, it's "the best language going today, which is to say, it's the marginally acceptable one among the set of complete bagbiting loser languages that we have to work with out here in the real world."

真的,你应该读读他那篇文章

Really, you should read it.

Java 几乎每一方面都很好,除了它的语言本身,而这是 JWZ 抱怨的主要对象。但那是一个很大的抱怨。再好的库也救不了一个烂语言。相信我:你可能比我知道多得多的东西,但是我知道好兵救不了烂将。在 Geoworks 搞了五年汇编语言都会了我这个道理。

Java is truly wonderful along almost every dimension except for the language itself, which is mostly what JWZ was griping about. But that's a lot to gripe about. Libraries can only get you so far if your language sucks. Trust me: you may know many, many things better than I do, but I know that libraries can't really save a sucky language. Five years of assembly-language hell at Geoworks taught me that.

跟 C++ 比,Java 作为一个语言还过得去。好吧,别扯了,Java 要好很多。因为它有(内建)的字符串。哥们,你说一个没有内建的字符串的语言是人用的吗。

Compared to C++, Java as a language is about even. Well, scratch that, it's a lot better, because it has strings, oh man, how can you use a language with lousy string support.

但是 Java 跟 C++ 比少了一些好东西,比如(函数调用时)传引用,栈上的对象,typedef,宏,以及运算符重载。一些时不时地会很称手的东西。

But Java's missing some nice features from C++, such as pass-by-reference(-to-stack-object), typedefs, macros, and operator overloading. Stuff that comes in handy now and again.

哦,还有多重继承,我现在老了,反而挺欣赏了的多重继承。如果你认为我这个观点僵硬不灵活的家伙是多态教义很好的反例的话,我倒是可以给你举几个为什么你需要多态继承的好例子,或者至少像 Ruby 那样的 mixin 或者自动的派遣。下次问问我白龙马的事情。今天我要告诉你为什么 Java 的 interface 是个烂货。

Oh, and multiple inheritance, which now I've come to appreciate in my old age. If you think my Opinionated Elf was a good counterpoint to polymorphism dogma, I've got several brilliant examples of why you need multiple inheritance, or at least Ruby-style mixins or automatic delegation. Ask me about the Glowing Sword or Cloak of Thieving sometime. Interfaces suck.

几年前 Gosling 自己都说,如果一切都能重来的话,他不会搞出个 interface 的概念。

Gosling even said, a few years ago, that if he had to do it all over again, he wouldn't have used interfaces.

但是那正是 Java 的问题。当 James 说出那句话的时候,人们被雷到了。我甚至能感觉到那股雷劲儿,能感觉到 Sun 公司市场部和法务部的鸟人是多么想把 James 灭口,然后告诉大家他没那么说过。

But that's just exactly what the problem with Java is. When James said that, people were shocked. I could feel the shock waves, could feel the marketing and legal folks at Sun maneuvering to hush him up, brush it off, say it wasn't so.

Java 的问题就是人们都被那帮人搞的广告效应蒙住了眼。C++,Perl,任何流行语言都有这个问题。这是很严重的,因为如果没有一些说大话吹牛逼的广告,一个语言是不会流行起来的。所以如果一个语言的设计者说他的语言没有被设计得很完美的话,就是赶紧用麻醉枪射击这胡说八道的家伙并关闭会议的时候了。

The problem with Java is that people are blinded by the marketing hype. That's the problem with C++, with Perl, with any language that's popular, and it's a serious one, because languages can't become popular without hype. So if the language designer suggests innocently that the language might not have been designed perfectly, it's time to shoot the language designer full of horse tranquilizers and shut down the conference.

语言们需要放点儿卫星才能活,我只希望人们不要被卫星耀瞎了眼。

Languages need hype to survive; I just wish people didn't have to be blinded by it.

我学了面向对象编程, 我自己也对此大吹大擂。当我加入亚马逊时,我不能告诉你我有什么智慧或者经验,但我可以给你背诵出所有关于 OOP 的魔咒。多重继承是邪恶的,因为大家都这么说; 运算符重载是邪恶的,诸如此类。我甚至有点模糊地知道为什么是邪恶的,但实际上不知道。后来我明白了,这些都不邪恶,不是烂玩意儿,烂的是开发者,是我。我现在还是烂,但是希望每年都不烂一点起来。

I drank the OOP Kool-Aid, I regurgitated the hype myself. When I started at Amazon, I could recite for you all the incantations, psalms, and voodoo chants that I'd learned, all in lieu of intelligence or experience, the ones that told me Multiple Inheritance is Evil 'cuz Everyone Says So, and Operator Overloading Is Evil, and so on. I even vaguely sort of knew why, but not really. Since then I've come to realize that it's not MI that sucks, it's developers who suck. I sucked, and I still do, although hopefully less every year.

上礼拜我碰到一个来面试的,他告诉我多继承是邪恶的,因为,比如,你可以从头,胳膊,腿,躯干多重继承出一个人来。他既是对的,又是错的。那样的多继情形当然邪恶,但那都是因为他自己太邪恶了。那样继承出来的“东西”远远就能看见有多蠢,如果他还把这玩意儿弄进门来那就更邪恶了。

I had an interview candidate last week tell me that MI is Evil because, for instance, you could make a Human class that multiply-inherits from Head, Arm, Leg, and Torso. He was both right and wrong. That MI situation was evil, sure, but it was all him. Stupid from a distance, evil if he'd made it in through the front door.

不良开发者,占了这世上开发者的大多数,他们能用你扔给他们随便什么语言写出不良的代码。

Bad developers, who constitute the majority of all developers worldwide, can write bad code in any language you throw at them.

说了这些,还是得说回来,多继承不是请客吃饭那么轻松的事儿; mixin 看起来是更好的解决方案,但是还没人完美的解决这个问题。但我还是认为 Java 比 C++ 好,即使它没有多继。因为我知道不管我的出发点是多么好,某一天我还是会被一堆不懂怎么写好代码的人包围,让他们用 Java 比用 C++ 会带来更少的伤害。

That said, though, MI is no picnic; mixins seem to be a better solution, but nobody has solved the problem perfectly yet. But I'll still take Java over C++, even without MI, because I know that no matter how good my intentions are, I will at some point be surrounded by people who don't know how to code, and they will do far less damage with Java than with C++.

此外,Java 除了语言本身外还有老多其他的重要有用的东西。且 Java 语言本身也在进化,虽然像冰川一样慢,所以我们还是能看到希望。Java 正是我们应该在亚马逊推荐使用的语言。

Besides, there's way more to Java than the core language. And even the language is evolving, albeit glacially, so there's hope. It's what we should be using at Amazon.

你就是得小心点儿,因为和其他任何语言一样,你能很容易找出一堆人,他们很懂一门语言及其编程环境,但对品味,计算或者其他任何重要的东西却一无所知。

You just have to be careful, because as with any other language, you can easily find people who know a lot about the language environment, and very little about taste, computing, or anything else that's important.

当你有怀疑时,还是雇那种会好几门语言的 Java 程序员,那种厌憎 J2EE/EJB 之类松松跨跨的所谓框架的,那种使用 Emacs 的。这都是一些实战经验。

When in doubt, hire Java programmers who are polyglots, who detest large spongy frameworks like J2EE and EJB, and who use Emacs. All good rules of thumb.

Perl

Perl,怎么说呢?

Perl. Where to start?

Perl 是个老朋友。老老朋友。我开始写 Perl 代码的时候,可能是 1995 年。而它为我很好的服务了差不多 10 年的时间。

Perl is an old friend. Perl and I go way back. I started writing Perl stuff in maybe 1995, and it's served me well for nearly a decade.

它就像你骑了十万二十万英里的老自行车,你心里永远有一块地方装着它,虽然现在你已经换了一辆更加现代化的只有五磅重的自行车,而且这一辆也不像老的那辆顶得你屁眼疼了。

It's like that old bicycle you've put 100k or 200k miles on, and you'll always have a warm fuzzy spot for it, even though you've since moved on to a more modern bike that weighs 5 lbs and doesn't make your ass hurt so much.

Perl 受欢迎原因有仨:

1. 用 Perl 你很快就能搞定你的问题。而这是最终的衡量标准。
1. Perl 有世上最好的市场推广。你可以写一本介绍他们市场推广有多绝的书。Sun 公司砸大笔钱给 Java 推市场,Perl 在受欢迎程度来说能跟 Java 齐头并进,但 Perl 纯粹是依靠 Larry Wall 和他那帮哥们的三寸不烂之舌做市场。哈佛商学院的人应该去研究 Perl 的市场是怎么做出来的。真的让人瞠目结舌。
1. 直到差不多,呃,现在,Perl 没有真正的竞争者。

Perl is popular for three reasons:

1. You can <em>get stuff done</em> really fast in Perl, which is what really matters, in the end.
1. Perl has the best marketing in the world. You could write a book about how brilliant their marketing is. Sun has marketed Java with money, and Perl is almost keeping up, popularity-wise, purely on the on sheer marketing brilliance of Larry Wall and his buddies. Folks at Harvard Business School should study Perl's marketing. It's astonishing.
1. Until roughly, oh, <em>now</em>, it had no real competitors.

有比 Perl “好”的语言。操,有很多比 Perl 好的语言,如果你定义“好”为“不是给疯子用的”的话。Lisp, Smalltalk, Python,妈呀,我可能可以列出二三十种比 Perl “好”的语言。从这些语言不像这个夏天在台湾街头爆了肚皮的抹香鲸这个角度来说。鲸鱼肠子到处都是,汽车上,机车上,行人身上。这就是 Perl。让人着迷,真的。

There are "better" languages than Perl — hell, there are lots of them, if you define "better" as "not being insane". Lisp, Smalltalk, Python, gosh, I could probably name 20 or 30 languages that are "better" than Perl, inasmuch as they don't look like that Sperm Whale that exploded in the streets of Taiwan over the summer. Whale guts everywhere, covering cars, motorcycles, pedestrians. That's Perl. It's charming, really.

但是 Perl 有很多很多好的特性,直到最近,都是其他语言没有的。它们弥补了 Perl 肠子在外的不足。你可以从爆了肚皮的鲸鱼可以做很多有用的东西出来,比如香水。这很有用。Perl 也是这样。

But Perl has many, many things going for it that, until recently, no other language had, and they compensated for its exo-intestinal qualities. You can make all sorts of useful things out of exploded whale, including perfume. It's quite useful. And so is Perl.

当其他的那些语言(尤其是 Lisp 和 Smalltalk)都想假装操作系统并不存在,列表(Lisp 的)和对象(Smalltalk 的)就是把屎搞出来的唯一存在,Perl 却走了截然相反的路子。Larry 说:Unix 和字符串是搞出屎来的唯一存在。

While all those other languages (Lisp and Smalltalk being particularly noteworthy offenders) tried to pretend that operating systems don't exist, and that lists (for Lisp) or objects (for Smalltalk) are the be-all, end-all of getting shit done, Perl did exactly the opposite. Larry said: Unix and string processing are the be-all, end-all of getting shit done.

对很多任务来说,他绝对是正确的。所以 Perl 绝对是 Unix 系统管理和字符串处理的史上最强语言,除了一个,刚出来的一个,从哥斯拉(电影哥斯拉看过没)之地出来的一个。我一会儿会讲到那一个。

And for many tasks, he was absolutely right. So Perl is better at Unix integration and string processing than any language on the planet, save one, and that one only arrived on the scene recently, from the land of Godzilla. I'll get to that one later.

可惜,Larry 太太太太在意 Unix 系统管理和字符串处理以致他压根忘了列表和对象,等他明白过来想改正的时候已经晚了。实际上,在 Perl 早期的…好吧,对鲸鱼肠子我实在不想用“设计”这个词,就说生命周期中吧,他犯的几个关键错误让把列表和对象加进来变得如此尴尬,以致 Perl 已经进化成一个真正的 Rube Goldberg 机器,至少当你想在 Perl 里用列表和对象的时候。(Rube Goldberg 是一漫画家,常画一些很复杂的机器,但只完成简单的工作,比如一个小球滚过很多关卡,最后把门打开。译者注)。

Sadly, Larry focused sooooo hard on Unix integration and string processing that he totally forgot about lists and objects until it was far too late to implement them properly. In fact, a few key mistakes he made early on in Perl's... well, I hesitate to use the word "design" for whale guts, but let's call it Perl's "lifecycle" — those mistakes made it so hard to do lists and objects correctly that Perl has evolved into a genuine Rube Goldberg machine, at least if you want to use lists or objects.

列表和对象也他妈的是很重要的,Larry!(farging 应该是作者不想说 fucking 那么直白,译者注)

Lists and objects are pretty farging important too, Larry!

Perl 没法表达列表因为 Larry 一早犯了一个悲剧性的愚蠢的错误,把列表全抹平。于是(1, 2, (3, 4))魔术般地变成(1, 2, 3, 4)。不是说你会想让它这样工作,而是 Larry 刚好那天在搞一个这样会更方便的问题。于是 Perl 的数据结构从此就变得爆炸了的鲸鱼了。

Perl can't do lists because Larry made the tragically stupid decision early on to flatten them automatically. So (1, 2, (3, 4)) magically becomes (1, 2, 3, 4). Not that you ever want it to work this way. But Larry happened to be working on some problem for which it was convenient on that particular day, and Perl's data structures have been pure exploded whale ever since.

今天你看 Perl 的书,小教程或 PPT 的时候,不花三分之一的时间在“引用”上是不可能的。这就是 Larry 可怜的,坏了的,Goldberg (漫画家,想起来没? 译者注)式的对他那抹平列表的疯狂错误的解决方案。但是 Perl 的市场宣传做得那么难以置信地好以致它让你觉得这是你身上发生过的最好的东西。你可以对任何东西取它的引用。这很有趣!闻起来也很香(说肠子呢,译者注,呵呵)!

Now you can't read a book or tutorial or PowerPoint on Perl without spending at least a third of your time learning about "references", which are Larry's pathetic, broken, Goldbergian fix for his list-flattening insanity. But Perl's marketing is so incredibly good that it makes you feel as if references are the best thing that ever happened to you. You can take a reference to anything! It's fun! Smells good, too!

Perl 不能支持面向对象编程因为 Larry 压根不相信这玩意儿。这可能没什么大不了; 我也不是很确定我是不是信这个 OOP。但是那么为啥他又要试着把对象加进 Perl 呢? Perl 的面向对象是个半成品,且在 Perl 社区里没多少人重视。它就是不像字符串处理或 Unix 集成那样充满灵感。

Perl can't do objects because Larry never reeeeally believed in them. Maybe that's OK; I'm still not quite sure if I believe in them either. But then why did he try adding them? Perl's OO is a halfhearted add-on that never caught on with the Perl community. It's just not as inspired as the string-processing or Unix integration stuff.

当然了,Perl 还有其他很多怪怪的特性。比如它的“上下文”,这是 Larry 要有 N 个变量名字空间的喜剧式决定的一个恐怖片式的产物。这些空间由 sigil 来区分(就是 Perl 里变量名前面的‘$’,‘@’,‘%’字符),看着像是从 shell 脚本里拷贝来的。在 Perl 里,所有的运算符,所有的函数,所有的操作其行为都是六取一的随机的,取决于当前的“上下文”。没有一些规则或助记法能帮你搞定这些特定操作在特定上下文里的特定行为。你得把它们全记在脑子里。

And of course, Perl has plenty of other crackpot design features. Take its "contexts", for instance, which are a horrid outgrowth of Larry's comical decision to have N variable namespaces, dereferenced by sigils, which he sort of copied from shell-script. In Perl, every operator, every function, every operation in the language behaves randomly in one of six different ways, depending on the current "context". There are no rules or heuristics governing how a particular operation will behave in a given context. You just have to commit it all to memory.

想要个例子? 这儿有一个:在一个值量(scalar,对应于 vector,向量)上下文里对一个哈希取值你得到一个字符串,里面是个分数,分子是目前已分配的键,分母是总共有多少个桶。鲸鱼肠子,我告诉你。

Need an example? Here's one: accessing a hash in a scalar context gives you a string containing a fraction whose numerator is the number of allocated keys, and the denominator is the number of buckets. Whale guts, I'm telling you.

但就像我说的—直到最近,没啥能像 Perl 那样把屎搞定。

Like I said, though — until recently, nothing could get the job done like Perl could.

Ruby

每过 15 年左右,一门语言就会被更好的代替。C 被 C++ 代替,至少对大应用开发而又需要性能和数据类型的人们来说。C++ 被 Java 代替,而 Java 无疑在 7 年后又会被更好的东西代替—好吧,我说的是完全代替 C++ 的 7 年后,这到目前为止还没有发生,主要是因为微软能在 Java 霸占桌面系统之前狙击它。但是在服务器上的应用而言,C++ 的阵地已经慢慢让给 Java 了。

Every 15 years or so, languages are replaced with better ones. C was replaced by C++, at least for large-scale application development by people who needed performance but desperately wanted data types too. C++ is being replaced by Java, and Java will doubtless be replaced with something better in seven years — well, seven years after it finishes replacing C++, which evidently hasn't fully happened yet, mostly because Microsoft was able to stall it before it became ubiquitous on the desktop. But for server-side applications, C++ is basically on its way out.

Perl 有一天也会消逝。那是因为一门新的语言 Ruby 刚刚终于被翻译成英语了。没错,它是在日本发明的,这么多地儿,没想到日本人搞出来了,还以为他们只是硬件和制造上占有名气,而不是他们的软件业,所以大家都跟你一样惊奇。为什么呢,大家可能都在想。但是我认为这都是跟打字有关。我根本不能想象他们以前能打字打得足够快,英文字母只有 26 个,他们却有上万个字。但是 Emacs 几年前支持多字节字符了,所以我猜他们现在打字速度他妈的快多了。(所以能搞出 Ruby 来了,译者猜作者是这个意思) (是的,他们也用 Emacs —— 事实上日本人负责了 Emacs 多字节支持的大部工作,而且搞得坚不可摧。)

Perl will be gone soon, too. That's because a new language called Ruby has finally been translated into English. Yep, it was invented in Japan, of all places — everyone else was as surprised as you are, since Japan's known for its hardware and manufacturing, but not for its software development. Why, is anyone's guess, but I'm thinking it's the whole typing thing; I just can't imagine they were able to type fast enough before, what with having an alphabet with ten thousand characters in it. But Emacs got multibyte support a few years ago, so I can imagine they're pretty dang fast with it now. (And yes, they use Emacs — in fact Japanese folks did the majority of the Mule [multibyte] support for Emacs, and it's rock-solid.)

不管怎么样,Ruby 从 Perl 那里偷师了所有的好东西; 实际上,Matz, Ruby 的作者(Yukihiro Matsumoto,如果我没记错的话,但是他外号“Matz”),觉得他从 Perl 那里偷的有点太多了,他的鞋上也粘了些鲸鱼肠子。但是只是一丢丢。

Anyway, Ruby stole everything good from Perl; in fact, Matz, Ruby's author (Yukihiro Matsumoto, if I recall correctly, but he goes by "Matz"), feels he may have stolen a little too much from Perl, and got some whale guts on his shoes. But only a little.

最重要的是,Ruby 拿来了 Perl 的串处理和 Unix 集成,一点没改,就是说语法都是一样的,于是乎啥也不说了,你就拥有了 Perl 最好的那部分。这是个不错的开局,特别是如果你不把 Perl 剩下的东西也拿进来的话。

For the most part, Ruby took Perl's string processing and Unix integration as-is, meaning the syntax is identical, and so right there, before anything else happens, you already have the Best of Perl. And that's a great start, especially if you don't take the Rest of Perl.

但是之后 Matz 还从 Lisp 那里拿来的最好的列表处理,Smalltalk 和其他语言那里拿来了最好的面向对象,CLU 那里拿来了最好的迭代器,以及基本上是每个人每个事的最好的东西。

But then Matz took the best of list processing from Lisp, and the best of OO from Smalltalk and other languages, and the best of iterators from CLU, and pretty much the best of everything from everyone.

而他让这些东西全部都跑起来,跑得那么顺,你都不会注意到这些东西在那儿。我比其他任何语言都快就学会了 Ruby,我总共会三十到四十门语言; 而我花了大概三天时间就能用 Ruby 比 Perl 还流畅地工作了,当了八年的 Perl 黑客后。这些东西是这么的和谐你都能自己猜它们是怎么工作的,而且大多数时候你都能猜对。漂亮。有趣。靠谱。

And he somehow made it all work together so well that you don't even notice that it has all that stuff. I learned Ruby faster than any other language, out of maybe 30 or 40 total; it took me about 3 days before I was more comfortable using Ruby than I was in Perl, after eight years of Perl hacking. It's so consistent that you start being able to guess how things will work, and you're right most of the time. It's beautiful. And fun. And practical.

如果把语言比成自行车,那么 AWK 就是一辆粉系的儿童自行车,前面有个白色小框,还插块小旗,Perl 就是沙滩车(还记得那有多酷吧? 唉。),而 Ruby 则是一辆七千五美金的钛合金山地自行车。从 Perl 飞跃到 Ruby 意义不下于从 C++ 到 Java 的飞跃。却没有任何缺陷,因为 Ruby 几乎是 Perl 功能的一个超集,而 Java 却拿掉了一些人们想要的东西,且没有真正的提供一个替代品。

If languages are bicycles, then Awk is a pink kiddie bike with a white basket and streamers coming off the handlebars, Perl is a beach cruiser (remember how cool they were? Gosh.) and Ruby is a $7,500 titanium mountain bike. The leap from Perl to Ruby is as significant as the leap from C++ to Java, but without any of the downsides, because Ruby's essentially a proper superset of Perl's functionality, whereas Java took some things away that people missed, and didn't offer real replacements for them.

下次我会写更多关于 Ruby 的东西。我先需要灵感。去读读 Lucky Stiff 的(poignant) guide to Ruby 吧。那本书是一本有灵感的书。真的,读一下。超赞。我不理解产生它的那种头脑,但它很有趣,很犀利,且全是关于 Ruby 的。好像。你会看到的。

I'll write more about Ruby sometime. I need to be inspired first. Read Why the Lucky Stiff's (poignant) guide to Ruby. That is an inspired piece of work. Really. Read it. It's amazing. I don't understand the kind of mind that could produce it, but it's funny, and poignant, and all about Ruby. Sort of. You'll see.

Python

啊,Python 怎么说呢,一个不错的语言,这么多年来一直旁边在等待它的机会? Python 社区很长时间以来是那些勇敢地吞下红药片从 Perl 骇客帝国中醒来的人的避难营。

Well gosh, what about Python, a nice language that has patiently been waiting in the wings for all these years? The Python community has long been the refuge for folks who finally took the red pill and woke up from the Perl Matrix.

啊,有点像 Smalltalk 的人们,他们永远在等待替代 C++,没想到半路杀出 Java 一下把它们操翻了,漂亮地,永久地。哎哟。Ruby 正在对 Python 做着同样的事,现在,今天。可能会在一夜之间吧。

Well, they're just like the Smalltalk folks, who waited forever to replace C++, and then Java came along and screwed them royally, and permanently. Oops. Ruby's doing exactly that to Python, right now, today. Practically overnight.

Python 本来可以统治世界,可惜它有两个致命缺陷:空格,和冷淡。

Python would have taken over the world, but it has two fatal flaws: the whitespace thing, and the permafrost thing.

空格很简单,就是说 Python 是用缩进来表达代码块之间的嵌套。它强制你必须按一定格式把所有的东西缩进,他们这样做是为了让所有人写的代码看上去一样。不料蛮多程序员讨厌这点,因为他们觉得自己的自由被拿走了; 感觉就像 Python 侵犯了宪法赋予他们的可以随便缩进格式和全写在一行上的权利。

The whitespace thing is simply that Python uses indentation to determine block nesting. It forces you to indent everything a certain way, and they do this so that everyone's code will look the same. A surprising number of programmers hate this, because it feels to them like their freedom is being taken away; it feels as if Python is trampling their constitutional right to use shotgun formatting and obfuscated one-liners.3

Python 的作者,Guido Van Rossum,也在早期犯过一些很傻的技术错误 —— 没有像 Larry 的失误那么严重,但是还是有几个。比如,最早 Python 没有字面变量范围,但它同时也没有动态变量范围,而动态变量范围可能会有它一些问题,但它还是有用的。Python 却没有这些,只有全局的和本地(函数)的两种范围。所以即使它是一个真正的 OO 系统,类甚至不能访问它们自己的动态成员变量。你必须给成员函数传“self”参数,一大堆 self 参数很快就会把你搞疯掉,即使你不在意空格问题。

Python's author, Guido Van Rossum, also made some boneheaded technical blunders early on — none quite as extravagant as Larry's blunders, but a few were real doozies nonetheless. For instance, Python originally had no lexical scoping. But it didn't have dynamic scoping either, and dynamic scoping may have its share of problems, but it at least sort of works. Python had NOTHING except for global and local (function) scope, so even though it had a "real" OO system, classes couldn't even access their own damned instance variables. You have to pass a "self" parameter to EVERY instance method and then get to your instance data by accessing it through self. So everything in Python is self, selfself, selfselfself, selfSELFselfSELF__SELF__, and it drives you frigging nuts, even if you don't mind the whitespace thing.

等等之类。

Etc.

但在我看来,Python 不行其实是因为冷淡。这阻止了它成为首选脚本语言,或者首选一切语言。靠,人们现在还在用 Tcl 作嵌入解释执行器,虽然 Python 比 Tcl 好得不要太多 —— 除了,我说,这个冷淡问题。

But in my opinion, it's really the frost thing that killed Python, and has prevented it from ever achieving its wish to be the premier scripting language, or the premier anything language, for that matter. Heck, people still use Tcl as an embedded interpreter, even though Python is far superior to Tcl in every conceivable way — except, that is, for the frost thing.

(此处开始我不知所云。呵呵,这样吧,把原文贴在最后面。译者注)

What’s the frost thing, you ask? Well, I used to have a lot of exceptionally mean stuff written here, but since Python’s actually quite pleasant to work with (if you can overlook its warts), I no longer think it’s such a great idea to bash on Pythonistas。The “frost thing” is just that they used to have a tendency to be a bit, well, frosty。Why?

Because they were so tired of hearing about the whitespace thing!

I think that’s why Python never reached Perl’s level of popularity, but maybe I’m just imagining things。

Coda

这才是我真正想给亚马逊开发者杂志写的文章。或者至少是这样的。出于某些原因,我的真感情好像只有在我凌晨三点到六点失眠的时候都会流露。该睡觉了!我下个会议再过两小时就开始了。

That was the ADJ article I really wanted to write。Or at least something like it。For some reason, though, my true feelings only seem to come out during insomniac attacks between 3am and 6am。Time for bed!2 hours ’til my next meeting。

注1,Eric 告诉我当时几乎全是 Jamie Zawinski,当他们在 Lucid 工作的时候。

注2,我写了这个之后很多人告诉我 Paul Graham 是用 VI 的,想不到。

注3,为了有据可查,我个人根本不介意空格问题。我认为因为这个而不喜欢 Python 是很傻的。我只是说有一堆比例让人惊奇的其他工程师讨厌空格问题。