编程即创造:黑客与画家的共通之道
Paul Graham 在本文中论证:黑客与画家本质上是同一种人——他们都是制造者(makers),而非科学家或工程师。编程不是冷冰冰的工程,而是像绘画一样充满创造、迭代和美学追求的过程。他批评大学把编程当作“计算机科学”来教,导致学生误以为必须先设计后编码;他主张编程应像画家一样“打草稿”,先写烂代码再逐步打磨。Graham 还强调共情(empathy)对优秀黑客的重要性,认为能站在用户和读者角度思考才是写出伟大软件的关键。本文适合所有希望理解编程创造力本质的开发者。
When I finished grad school in computer science I went to art school to study painting. A lot of people seemed surprised that someone interested in computers would also be interested in painting. They seemed to think that hacking and painting were very different kinds of work-- that hacking was cold, precise, and methodical, and that painting was the frenzied expression of some primal urge.
Both of these images are wrong. Hacking and painting have a lot in common. In fact, of all the different types of people I've known, hackers and painters are among the most alike.
What hackers and painters have in common is that they're both makers. Along with composers, architects, and writers, what hackers and painters are trying to do is make good things. They're not doing research per se, though if in the course of trying to make good things they discover some new technique, so much the better.
当我读完计算机科学的研究生后,我去艺术学院学习绘画。很多人似乎很惊讶,一个对计算机感兴趣的人竟然也对绘画感兴趣。他们似乎认为黑客和绘画是非常不同的工作——黑客是冰冷、精确、有条理的,而绘画是某种原始冲动的狂热表达。
这两种印象都是错误的。黑客和绘画有很多共同点。事实上,在我认识的所有不同类型的人中,黑客和画家是最相似的。
黑客和画家的共同之处在于他们都是创造者。和作曲家、建筑师、作家一样,黑客和画家试图做的是创造出美好的东西。他们本身并不是在做研究,尽管在努力创造美好事物的过程中,如果他们发现了一些新技术,那当然更好。
I've never liked the term "computer science." The main reason I don't like it is that there's no such thing. Computer science is a grab bag of tenuously related areas thrown together by an accident of history, like Yugoslavia. At one end you have people who are really mathematicians, but call what they're doing computer science so they can get DARPA grants. In the middle you have people working on something like the natural history of computers-- studying the behavior of algorithms for routing data through networks, for example. And then at the other extreme you have the hackers, who are trying to write interesting software, and for whom computers are just a medium of expression, as concrete is for architects or paint for painters. It's as if mathematicians, physicists, and architects all had to be in the same department.
我从来不喜欢“计算机科学”这个术语。我不喜欢它的主要原因是,根本就没有什么计算机科学。计算机科学是一个大杂烩,由一些关联松散、因历史偶然拼凑在一起的领域组成,就像南斯拉夫一样。一端是那些实际上是数学家的人,但他们把自己做的事情称为计算机科学,以便获得DARPA的资助。中间是一些研究计算机自然史的人——例如,研究路由数据通过网络的算法行为。另一端是黑客,他们试图编写有趣的软件,对他们来说,计算机只是一种表达媒介,就像混凝土对于建筑师、颜料对于画家一样。这就好像数学家、物理学家和建筑师都必须待在同一个系里。
Sometimes what the hackers do is called "software engineering," but this term is just as misleading. Good software designers are no more engineers than architects are. The border between architecture and engineering is not sharply defined, but it's there. It falls between what and how: architects decide what to do, and engineers figure out how to do it.
What and how should not be kept too separate. You're asking for trouble if you try to decide what to do without understanding how to do it. But hacking can certainly be more than just deciding how to implement some spec. At its best, it's creating the spec-- though it turns out the best way to do that is to implement it.
有时黑客所做的工作被称为“软件工程”,但这个术语同样具有误导性。优秀的软件设计师并不比建筑师更像是工程师。建筑与工程之间的界限并不清晰,但它确实存在。它介于做什么和怎么做之间:建筑师决定做什么,工程师则想办法如何实现。
做什么和怎么做不应该被分隔得太开。如果你试图在不了解如何做的情况下决定做什么,那是在自找麻烦。但黑客的工作当然不仅仅是决定如何实现某个规范。在最好的情况下,它是创造规范——尽管事实证明最好的方式是通过实现来创造规范。
Perhaps one day "computer science" will, like Yugoslavia, get broken up into its component parts. That might be a good thing. Especially if it meant independence for my native land, hacking.
Bundling all these different types of work together in one department may be convenient administratively, but it's confusing intellectually. That's the other reason I don't like the name "computer science." Arguably the people in the middle are doing something like an experimental science. But the people at either end, the hackers and the mathematicians, are not actually doing science.
The mathematicians don't seem bothered by this. They happily set to work proving theorems like the other mathematicians over in the math department, and probably soon stop noticing that the building they work in says ``computer science'' on the outside. But for the hackers this label is a problem. If what they're doing is called science, it makes them feel they ought to be acting scientific. So instead of doing what they really want to do, which is to design beautiful software, hackers in universities and research labs feel they ought to be writing research papers.
也许有一天,“计算机科学”会像南斯拉夫一样解体成各个组成部分。那可能是一件好事,尤其如果这意味着我的故土——黑客——获得独立的话。
把所有这些不同类型的工作捆绑在一个系里,行政上可能方便,但思想上却令人困惑。这是我不喜欢“计算机科学”这个名字的另一个原因。可以说,中间的那些人是在做类似实验科学的工作。但两端的黑客和数学家实际上并不是在做科学。
数学家似乎并不为此困扰。他们愉快地像数学系的数学家一样证明定理,可能很快就忘记了他们所在大楼外面写着“计算机科学”。但对黑客来说,这个标签是个问题。如果他们所做的工作被称为科学,他们会觉得自己应该表现得像科学一样。因此,大学和研究实验室的黑客们没有去做他们真正想做的事——设计漂亮的软件——反而觉得应该写研究论文。
In the best case, the papers are just a formality. Hackers write cool software, and then write a paper about it, and the paper becomes a proxy for the achievement represented by the software. But often this mismatch causes problems. It's easy to drift away from building beautiful things toward building ugly things that make more suitable subjects for research papers.
Unfortunately, beautiful things don't always make the best subjects for papers. Number one, research must be original-- and as anyone who has written a PhD dissertation knows, the way to be sure that you're exploring virgin territory is to stake out a piece of ground that no one wants. Number two, research must be substantial-- and awkward systems yield meatier papers, because you can write about the obstacles you have to overcome in order to get things done. Nothing yields meaty problems like starting with the wrong assumptions. Most of AI is an example of this rule; if you assume that knowledge can be represented as a list of predicate logic expressions whose arguments represent abstract concepts, you'll have a lot of papers to write about how to make this work. As Ricky Ricardo used to say, "Lucy, you got a lot of explaining to do."
The way to create something beautiful is often to make subtle tweaks to something that already exists, or to combine existing ideas in a slightly new way. This kind of work is hard to convey in a research paper.
在最好的情况下,论文只是一种形式。黑客们写出很酷的软件,然后写一篇关于它的论文,论文就成了软件所代表成就的代理。但通常这种不匹配会引发问题。很容易从构建漂亮的东西转向构建丑陋的东西,后者更适合作为研究论文的主题。
不幸的是,漂亮的东西并不总是最适合写论文的题材。第一,研究必须具有原创性——任何写过博士论文的人都知道,确保你探索的是处女地的方法就是划出一块没人想要的地盘。第二,研究必须有实质内容——别扭的系统能产生更有料的论文,因为你可以写为了完成工作而克服的障碍。没有什么比从错误假设开始更能产生有料的问题了。人工智能的大部分历史都是这条规则的例子;如果你假设知识可以表示为谓词逻辑表达式的列表,其参数代表抽象概念,那么你就会有很多论文要写,关于如何让这玩意工作。正如Ricky Ricardo常说的:“Lucy,你有很多要解释的了。”
创造美丽事物的方式往往是对已有的东西进行微妙的调整,或者以一种略微新颖的方式结合已有的想法。这种工作在研究论文中很难表达。
So why do universities and research labs continue to judge hackers by publications? For the same reason that "scholastic aptitude" gets measured by simple-minded standardized tests, or the productivity of programmers gets measured in lines of code. These tests are easy to apply, and there is nothing so tempting as an easy test that kind of works.
Measuring what hackers are actually trying to do, designing beautiful software, would be much more difficult. You need a good sense of design to judge good design. And there is no correlation, except possibly a negative one, between people's ability to recognize good design and their confidence that they can.
The only external test is time. Over time, beautiful things tend to thrive, and ugly things tend to get discarded. Unfortunately, the amounts of time involved can be longer than human lifetimes. Samuel Johnson said it took a hundred years for a writer's reputation to converge. You have to wait for the writer's influential friends to die, and then for all their followers to die.
那么,为什么大学和研究实验室继续以出版物来评判黑客呢?原因与用简单的标准化测试来衡量“学术能力”,或用代码行数来衡量程序员生产力一样。这些测试易于应用,没有什么比一个勉强有效且容易实施的测试更诱人了。
衡量黑客真正想做的事——设计漂亮的软件——要困难得多。你需要良好的设计感才能判断好的设计。而人们识别优秀设计的能力与他们对自己判断力的信心之间,没有任何关联——甚至可能是负相关。
唯一的外部标准是时间。随着时间的推移,美好的事物往往兴盛,丑陋的事物往往被抛弃。不幸的是,所需的时间可能比人的寿命还长。塞缪尔·约翰逊说过,一个作家的声誉需要一百年才能稳定下来。你得等作家的有影响力朋友们死去,然后等他们所有的追随者也死去。
I think hackers just have to resign themselves to having a large random component in their reputations. In this they are no different from other makers. In fact, they're lucky by comparison. The influence of fashion is not nearly so great in hacking as it is in painting.
There are worse things than having people misunderstand your work. A worse danger is that you will yourself misunderstand your work. Related fields are where you go looking for ideas. If you find yourself in the computer science department, there is a natural temptation to believe, for example, that hacking is the applied version of what theoretical computer science is the theory of. All the time I was in graduate school I had an uncomfortable feeling in the back of my mind that I ought to know more theory, and that it was very remiss of me to have forgotten all that stuff within three weeks of the final exam.
Now I realize I was mistaken. Hackers need to understand the theory of computation about as much as painters need to understand paint chemistry. You need to know how to calculate time and space complexity and about Turing completeness. You might also want to remember at least the concept of a state machine, in case you have to write a parser or a regular expression library. Painters in fact have to remember a good deal more about paint chemistry than that.
我认为黑客们只能接受他们的声誉中有很大随机成分。在这方面,他们和其他创造者没什么不同。事实上,相比之下他们还算是幸运的。时尚的影响在黑客领域远没有在绘画领域那么大。
比人们误解你的工作更糟的是,你自己也误解自己的工作。相关领域是你寻找灵感的地方。如果你身处计算机科学系,你很容易自然而然地认为,黑客是理论计算机科学理论的应用版本。我在读研究生时,内心深处一直有一种不适感,觉得自己应该知道更多理论,而我在期末考试后三个星期内就把那些东西全忘了,这太不负责任了。
现在我知道我错了。黑客需要理解计算理论的程度,大约相当于画家需要理解颜料化学。你需要知道如何计算时间复杂度和空间复杂度,以及图灵完备性。你可能还需要至少记住状态机的概念,以防你要写一个解析器或正则表达式库。事实上,画家需要记住的颜料化学知识比这还要多得多。
I've found that the best sources of ideas are not the other fields that have the word "computer" in their names, but the other fields inhabited by makers. Painting has been a much richer source of ideas than the theory of computation.
For example, I was taught in college that one ought to figure out a program completely on paper before even going near a computer. I found that I did not program this way. I found that I liked to program sitting in front of a computer, not a piece of paper. Worse still, instead of patiently writing out a complete program and assuring myself it was correct, I tended to just spew out code that was hopelessly broken, and gradually beat it into shape. Debugging, I was taught, was a kind of final pass where you caught typos and oversights. The way I worked, it seemed like programming consisted of debugging.
For a long time I felt bad about this, just as I once felt bad that I didn't hold my pencil the way they taught me to in elementary school. If I had only looked over at the other makers, the painters or the architects, I would have realized that there was a name for what I was doing: sketching. As far as I can tell, the way they taught me to program in college was all wrong. You should figure out programs as you're writing them, just as writers and painters and architects do.
我发现,最好的灵感来源并不是那些名字里带“计算机”的领域,而是其他创造者所在的领域。绘画是比计算理论丰富得多的灵感源泉。
例如,我在大学里被教导,在接近计算机之前,应该先在纸上完全构思好一个程序。我发现我并不是这样编程的。我喜欢坐在电脑前编程,而不是在纸上。更糟糕的是,我没有耐心地写出一个完整的程序并确保它是正确的,而是倾向于喷出糟糕的代码,然后逐渐把它敲打成型。我学到的调试是一种最终阶段,用来捕捉拼写错误和疏忽。按照我的工作方式,编程似乎就是由调试组成的。
很长一段时间,我对此感到内疚,就像我曾经因为不像小学教的那样握笔而感到内疚一样。如果我当时看看其他创造者——画家或建筑师——我就会意识到我所做的事情有一个名字:草图(sketching)。据我所知,大学里教我的编程方式完全是错误的。你应该在编写程序的同时构思程序,就像作家、画家和建筑师那样。
Realizing this has real implications for software design. It means that a programming language should, above all, be malleable. A programming language is for thinking of programs, not for expressing programs you've already thought of. It should be a pencil, not a pen. Static typing would be a fine idea if people actually did write programs the way they taught me to in college. But that's not how any of the hackers I know write programs. We need a language that lets us scribble and smudge and smear, not a language where you have to sit with a teacup of types balanced on your knee and make polite conversation with a strict old aunt of a compiler.
意识到这一点对软件设计有实际的影响。这意味着编程语言首先应该是可塑的。编程语言是用来思考程序的,而不是用来表达你已构思好的程序。它应该是一支铅笔,而不是一支钢笔。如果人们真的像大学教我的那样写程序,静态类型倒是个好主意。但我认识的黑客没有一个是那样写程序的。我们需要一种语言,让我们可以涂鸦、涂抹、弄脏,而不是一种必须端着类型平衡在膝上,与一位严厉的编译器老姑妈礼貌交谈的语言。
While we're on the subject of static typing, identifying with the makers will save us from another problem that afflicts the sciences: math envy. Everyone in the sciences secretly believes that mathematicians are smarter than they are. I think mathematicians also believe this. At any rate, the result is that scientists tend to make their work look as mathematical as possible. In a field like physics this probably doesn't do much harm, but the further you get from the natural sciences, the more of a problem it becomes.
A page of formulas just looks so impressive. (Tip: for extra impressiveness, use Greek variables.) And so there is a great temptation to work on problems you can treat formally, rather than problems that are, say, important.
If hackers identified with other makers, like writers and painters, they wouldn't feel tempted to do this. Writers and painters don't suffer from math envy. They feel as if they're doing something completely unrelated. So are hackers, I think.
说到静态类型,认同自己为创造者能使我们避免困扰科学的另一个问题:数学嫉妒。科学界的每个人都暗自相信数学家比他们更聪明。我认为数学家也这么认为。无论如何,结果是科学家倾向于让他们的工作看起来尽可能数学化。在物理学这样的领域,这也许没什么大碍,但离自然科学越远,问题就越严重。
一页公式看起来就是那么令人印象深刻。(提示:要更令人印象深刻,使用希腊变量。)因此,人们很容易倾向于研究那些可以形式化处理的问题,而不是那些,比如说,重要的问题。
如果黑客认同自己是其他创造者,比如作家和画家,他们就不会被诱惑去做这种事。作家和画家没有数学嫉妒。他们感觉自己做的事情完全不相干。黑客也一样,我认为。
If universities and research labs keep hackers from doing the kind of work they want to do, perhaps the place for them is in companies. Unfortunately, most companies won't let hackers do what they want either. Universities and research labs force hackers to be scientists, and companies force them to be engineers.
I only discovered this myself quite recently. When Yahoo bought Viaweb, they asked me what I wanted to do. I had never liked the business side very much, and said that I just wanted to hack. When I got to Yahoo, I found that what hacking meant to them was implementing software, not designing it. Programmers were seen as technicians who translated the visions (if that is the word) of product managers into code.
如果大学和研究实验室阻止黑客做他们想做的工作,那么也许他们应该去公司。不幸的是,大多数公司也不会让黑客做他们想做的事。大学和研究实验室强迫黑客成为科学家,而公司强迫他们成为工程师。
我自己是最近才发现的。当雅虎收购Viaweb时,他们问我想做什么。我向来不太喜欢商业方面,所以我说只想做黑客。当我到了雅虎,我发现他们所说的黑客意味着实现软件,而不是设计软件。程序员被视为技术员,将产品经理的愿景(如果这个词合适的话)翻译成代码。
This seems to be the default plan in big companies. They do it because it decreases the standard deviation of the outcome. Only a small percentage of hackers can actually design software, and it's hard for the people running a company to pick these out. So instead of entrusting the future of the software to one brilliant hacker, most companies set things up so that it is designed by committee, and the hackers merely implement the design.
If you want to make money at some point, remember this, because this is one of the reasons startups win. Big companies want to decrease the standard deviation of design outcomes because they want to avoid disasters. But when you damp oscillations, you lose the high points as well as the low. This is not a problem for big companies, because they don't win by making great products. Big companies win by sucking less than other big companies.
So if you can figure out a way to get in a design war with a company big enough that its software is designed by product managers, they'll never be able to keep up with you. These opportunities are not easy to find, though. It's hard to engage a big company in a design war, just as it's hard to engage an opponent inside a castle in hand to hand combat. It would be pretty easy to write a better word processor than Microsoft Word, for example, but Microsoft, within the castle of their operating system monopoly, probably wouldn't even notice if you did.
The place to fight design wars is in new markets, where no one has yet managed to establish any fortifications. That's where you can win big by taking the bold approach to design, and having the same people both design and implement the product. Microsoft themselves did this at the start. So did Apple. And Hewlett-Packard. I suspect almost every successful startup has.
这似乎是大型公司的默认策略。他们这样做是为了降低结果的方差。只有一小部分黑客真正能够设计软件,而公司管理者很难选出这些人才。所以,大多数公司不是把软件的未来托付给一个杰出的黑客,而是设立委员会来设计,黑客们仅仅实现设计。
如果你想在某个时候赚钱,记住这一点,因为这是创业公司获胜的原因之一。大公司想要降低设计结果的方差,因为他们想避免灾难。但当你抑制波动时,你也会失去高点和低点。这对大公司来说不是问题,因为他们不是靠做出伟大的产品来获胜。大公司靠比其他大公司烂得少来获胜。
所以,如果你能找到一种方法,与一个软件由产品经理设计的大公司进行设计战争,他们将永远无法跟上你。不过,这些机会并不容易找到。与大公司进行设计战争很难,就像与城堡里的对手进行肉搏战一样困难。例如,写出一个比微软Word更好的文字处理器很容易,但微软在他们的操作系统垄断的城堡里,可能甚至不会注意到你做了。
进行设计战争的地方是新兴市场,那里还没有人建立防御工事。在那里,你可以通过大胆的设计方法,让同一个人既设计又实现产品,从而大获全胜。微软自己就是这样开始的。苹果也是。惠普也是。我推测几乎每一个成功的创业公司都是如此。
So one way to build great software is to start your own startup. There are two problems with this, though. One is that in a startup you have to do so much besides write software. At Viaweb I considered myself lucky if I got to hack a quarter of the time. And the things I had to do the other three quarters of the time ranged from tedious to terrifying. I have a benchmark for this, because I once had to leave a board meeting to have some cavities filled. I remember sitting back in the dentist's chair, waiting for the drill, and feeling like I was on vacation.
The other problem with startups is that there is not much overlap between the kind of software that makes money and the kind that's interesting to write. Programming languages are interesting to write, and Microsoft's first product was one, in fact, but no one will pay for programming languages now. If you want to make money, you tend to be forced to work on problems that are too nasty for anyone to solve for free.
所以构建优秀软件的一种方法是创办自己的创业公司。但这有两个问题。一是在创业公司里,你除了写软件外还得做很多其他事。在Viaweb,如果我能有四分之一的 time做黑客,我就觉得自己很幸运了。而另外四分之三的时间,我做的事从乏味到恐怖都有。我有一个衡量标准,因为我曾经不得不离开董事会去补牙。我记得坐在牙医的椅子上,等着钻头,感觉就像在度假。
创业公司的另一个问题是,能赚钱的软件和值得写的软件之间没有太多重叠。编程语言写起来很有趣,微软的第一个产品实际上就是一种编程语言,但现在没人愿意为编程语言付费了。如果你想赚钱,你往往被迫去解决那些没人愿意免费解决的棘手问题。
All makers face this problem. Prices are determined by supply and demand, and there is just not as much demand for things that are fun to work on as there is for things that solve the mundane problems of individual customers. Acting in off-Broadway plays just doesn't pay as well as wearing a gorilla suit in someone's booth at a trade show. Writing novels doesn't pay as well as writing ad copy for garbage disposals. And hacking programming languages doesn't pay as well as figuring out how to connect some company's legacy database to their Web server.
I think the answer to this problem, in the case of software, is a concept known to nearly all makers: the day job. This phrase began with musicians, who perform at night. More generally, it means that you have one kind of work you do for money, and another for love.
Nearly all makers have day jobs early in their careers. Painters and writers notoriously do. If you're lucky you can get a day job that's closely related to your real work. Musicians often seem to work in record stores. A hacker working on some programming language or operating system might likewise be able to get a day job using it.
所有创造者都面临这个问题。价格由供需决定,那些做起来有趣的事情的需求,远不及那些解决个人客户琐碎问题的需求。在非百老汇演戏的收入,远不如在展会上穿大猩猩服装站在别人摊位前高。写小说的收入,远不如为垃圾处理器写广告文案。而编写编程语言的收入,也远不如想办法将某家公司的遗留数据库连接到他们的Web服务器。
我认为对于软件来说,这个问题的答案是一个几乎所有创造者都知晓的概念:日间工作(day job)。这个短语最初来自音乐家,他们在晚上表演。更一般地说,它意味着你为了钱做一种工作,为了热爱做另一种。
几乎所有的创造者在职业生涯早期都有日间工作。画家和作家是出了名的这样。如果幸运的话,你可以找到一份与你真正工作密切相关的日间工作。音乐家似乎经常在唱片店工作。从事某种编程语言或操作系统开发的黑客,也许也能找到一份使用它的日间工作。
When I say that the answer is for hackers to have day jobs, and work on beautiful software on the side, I'm not proposing this as a new idea. This is what open-source hacking is all about. What I'm saying is that open-source is probably the right model, because it has been independently confirmed by all the other makers.
It seems surprising to me that any employer would be reluctant to let hackers work on open-source projects. At Viaweb, we would have been reluctant to hire anyone who didn't. When we interviewed programmers, the main thing we cared about was what kind of software they wrote in their spare time. You can't do anything really well unless you love it, and if you love to hack you'll inevitably be working on projects of your own.
当我说解决之道是黑客们有一份日间工作,同时在业余时间开发漂亮的软件时,我并不是在提出一个新想法。这正是开源黑客的宗旨。我想说的是,开源很可能是正确的模式,因为它已经被所有其他创造者独立证实了。
让我惊讶的是,任何雇主会不愿意让黑客参与开源项目。在Viaweb,我们不愿意雇用不参与开源项目的人。当我们面试程序员时,我们主要关心的是他们在业余时间编写什么样的软件。除非你热爱一件事,否则不可能做得真正好;如果你热爱黑客,你不可避免地会做自己的项目。
Because hackers are makers rather than scientists, the right place to look for metaphors is not in the sciences, but among other kinds of makers. What else can painting teach us about hacking?
One thing we can learn, or at least confirm, from the example of painting is how to learn to hack. You learn to paint mostly by doing it. Ditto for hacking. Most hackers don't learn to hack by taking college courses in programming. They learn to hack by writing programs of their own at age thirteen. Even in college classes, you learn to hack mostly by hacking.
Because painters leave a trail of work behind them, you can watch them learn by doing. If you look at the work of a painter in chronological order, you'll find that each painting builds on things that have been learned in previous ones. When there's something in a painting that works very well, you can usually find version 1 of it in a smaller form in some earlier painting.
I think most makers work this way. Writers and architects seem to as well. Maybe it would be good for hackers to act more like painters, and regularly start over from scratch, instead of continuing to work for years on one project, and trying to incorporate all their later ideas as revisions.
The fact that hackers learn to hack by doing it is another sign of how different hacking is from the sciences. Scientists don't learn science by doing it, but by doing labs and problem sets. Scientists start out doing work that's perfect, in the sense that they're just trying to reproduce work someone else has already done for them. Eventually, they get to the point where they can do original work. Whereas hackers, from the start, are doing original work; it's just very bad. So hackers start original, and get good, and scientists start good, and get original.
The other way makers learn is from examples. For a painter, a museum is a reference library of techniques. For hundreds of years it has been part of the traditional education of painters to copy the works of the great masters, because copying forces you to look closely at the way a painting is made.
Writers do this too. Benjamin Franklin learned to write by summarizing the points in the essays of Addison and Steele and then trying to reproduce them. Raymond Chandler did the same thing with detective stories.
Hackers, likewise, can learn to program by looking at good programs-- not just at what they do, but the source code too. One of the less publicized benefits of the open-source movement is that it has made it easier to learn to program. When I learned to program, we had to rely mostly on examples in books. The one big chunk of code available then was Unix, but even this was not open source. Most of the people who read the source read it in illicit photocopies of John Lions' book, which though written in 1977 was not allowed to be published until 1996.
因为黑客是创造者而非科学家,所以寻找隐喻的正确场所不是科学,而是其他类型的创造者。绘画还能教会我们关于黑客的什么?
我们可以从绘画的例子中学到(或至少确认)的一件事是如何学习黑客技能。绘画主要是通过实践学会的。黑客也是如此。大多数黑客不是通过上大学编程课程学会黑客的。他们十三岁时通过自己编写程序学会的。即使在大学课堂上,你也主要是通过实践来学习黑客。
因为画家留下了作品轨迹,你可以看到他们边做边学。如果你按时间顺序看一个画家的作品,你会发现每一幅画都建立在前一幅画中学到的东西之上。当画中有某个地方非常出色时,你通常能在更早的一幅画中找到它的小版本。
我认为大多数创造者都是这样工作的。作家和建筑师似乎也是如此。也许黑客应该更像画家那样,定期从头开始,而不是在一个项目上持续多年,并试图将所有后来的想法作为修订融入其中。
黑客通过实践学习这一事实,是黑客与科学不同的另一个标志。科学家不是通过实践来学习科学,而是通过做实验和习题集。科学家一开始做的工作是完美的,因为他们只是在重复别人已经为他们做过的工作。最终,他们达到了能做原创工作的程度。而黑客从一开始就在做原创工作,只是非常糟糕。所以黑客从原创开始,然后变好;科学家从优秀开始,然后变得原创。
创造者学习的另一种方式是通过范例。对画家来说,博物馆是技术的参考图书馆。几百年来,临摹大师作品一直是画家传统教育的一部分,因为临摹迫使你仔细观察一幅画是如何制作的。
作家也这样做。本杰明·富兰克林通过总结艾迪生和斯蒂尔文章中的要点,然后尝试重现来学习写作。雷蒙德·钱德勒也用同样的方法学习侦探小说。
同样,黑客可以通过看好的程序来学习编程——不仅看它们的功能,还要看源代码。开源运动的一个较少宣传的好处是它让学习编程变得更容易。当我学习编程时,我们主要依赖书中的例子。当时可用的一个大块代码是Unix,但它也不是开源的。大多数阅读源码的人是通过非法复印的John Lions的书来读的,那本书尽管写于1977年,但直到1996年才获准出版。
Another example we can take from painting is the way that paintings are created by gradual refinement. Paintings usually begin with a sketch. Gradually the details get filled in. But it is not merely a process of filling in. Sometimes the original plans turn out to be mistaken. Countless paintings, when you look at them in xrays, turn out to have limbs that have been moved or facial features that have been readjusted.
Here's a case where we can learn from painting. I think hacking should work this way too. It's unrealistic to expect that the specifications for a program will be perfect. You're better off if you admit this up front, and write programs in a way that allows specifications to change on the fly.
(The structure of large companies makes this hard for them to do, so here is another place where startups have an advantage.)
Everyone by now presumably knows about the danger of premature optimization. I think we should be just as worried about premature design-- deciding too early what a program should do.
The right tools can help us avoid this danger. A good programming language should, like oil paint, make it easy to change your mind. Dynamic typing is a win here because you don't have to commit to specific data representations up front. But the key to flexibility, I think, is to make the language very abstract. The easiest program to change is one that's very short.
我们可以从绘画中学到的另一个例子是绘画是通过逐步精化来创作的。绘画通常从草图开始,然后逐渐填充细节。但这不仅仅是填充的过程。有时最初的计划被证明是错误的。无数绘画在X光下显示出肢体被移动过,或面部特征被调整过。
这是一个我们可以从绘画中学习的地方。我认为黑客也应该这样做。期望程序的规范完美无缺是不现实的。如果你提前承认这一点,并以允许规格在开发过程中随时改变的方式来编写程序,你会做得更好。
(大公司的结构使得他们很难做到这一点,所以这是创业公司的另一个优势。)
现在大概所有人都知道过早优化的危险。我认为我们应该同样担心过早设计——过早地决定一个程序应该做什么。
正确的工具可以帮助我们避免这种危险。一个好的编程语言应该像油画颜料一样,让你容易改变主意。动态类型在此大获全胜,因为你无需事先承诺特定的数据表示。但灵活性的关键,我认为,是让语言非常抽象。最容易改变的程序是那些非常短的程序。
This sounds like a paradox, but a great painting has to be better than it has to be. For example, when Leonardo painted the portrait of Ginevra de Benci in the National Gallery, he put a juniper bush behind her head. In it he carefully painted each individual leaf. Many painters might have thought, this is just something to put in the background to frame her head. No one will look that closely at it.
Not Leonardo. How hard he worked on part of a painting didn't depend at all on how closely he expected anyone to look at it. He was like Michael Jordan. Relentless.
Relentlessness wins because, in the aggregate, unseen details become visible. When people walk by the portrait of Ginevra de Benci, their attention is often immediately arrested by it, even before they look at the label and notice that it says Leonardo da Vinci. All those unseen details combine to produce something that's just stunning, like a thousand barely audible voices all singing in tune.
Great software, likewise, requires a fanatical devotion to beauty. If you look inside good software, you find that parts no one is ever supposed to see are beautiful too. I'm not claiming I write great software, but I know that when it comes to code I behave in a way that would make me eligible for prescription drugs if I approached everyday life the same way. It drives me crazy to see code that's badly indented, or that uses ugly variable names.
这听起来像是一个悖论,但一幅伟大的画作必须比它应有的样子更好。例如,当达芬奇在国家美术馆画《吉内薇拉·德·班琪》时,他在她身后画了一棵杜松。他仔细地画了每一片叶子。许多画家可能会想,这只是背景中用来框住她头部的东西,没有人会那么仔细地看它。
但达芬奇不是。他在一幅画的某个部分上的努力程度,完全取决于他预期别人会多么仔细地看它。他就像迈克尔·乔丹,毫不松懈。
毫不松懈之所以获胜,是因为在整体上,那些看不见的细节变得可见。当人们走过《吉内薇拉·德·班琪》的画像时,他们的注意力常常立刻被它吸引,甚至在他们看标签并注意到它写着列昂纳多·达·芬奇之前。所有这些看不见的细节结合在一起,产生了令人惊叹的效果,就像一千个几乎听不见的声音一齐和谐歌唱。
伟大的软件同样需要对美的狂热奉献。如果你窥视好软件的内部,你会发现那些从不应被看到的部分也是美的。我并非声称自己写伟大的软件,但我知道,当涉及到代码时,我的行为方式如果用在日常生活中,足以让我有资格服用处方药。看到缩进乱七八糟的代码,或使用丑陋的变量名,会让我发疯。
If a hacker were a mere implementor, turning a spec into code, then he could just work his way through it from one end to the other like someone digging a ditch. But if the hacker is a creator, we have to take inspiration into account.
In hacking, like painting, work comes in cycles. Sometimes you get excited about some new project and you want to work sixteen hours a day on it. Other times nothing seems interesting.
To do good work you have to take these cycles into account, because they're affected by how you react to them. When you're driving a car with a manual transmission on a hill, you have to back off the clutch sometimes to avoid stalling. Backing off can likewise prevent ambition from stalling. In both painting and hacking there are some tasks that are terrifyingly ambitious, and others that are comfortingly routine. It's a good idea to save some easy tasks for moments when you would otherwise stall.
In hacking, this can literally mean saving up bugs. I like debugging: it's the one time that hacking is as straightforward as people think it is. You have a totally constrained problem, and all you have to do is solve it. Your program is supposed to do x. Instead it does y. Where does it go wrong? You know you're going to win in the end. It's as relaxing as painting a wall.
如果黑客只是一个实现者,把规格转换成代码,那么他就可以像挖沟一样从头到尾工作。但如果黑客是创造者,我们就必须考虑灵感。
在黑客中,像绘画一样,工作是有周期的。有时你对某个新项目感到兴奋,想要一天工作十六个小时。其他时候,似乎没有任何事情有趣。
要做好工作,你必须考虑到这些周期,因为它们受到你如何应对它们的影响。当你驾驶手动挡汽车上坡时,有时需要松开离合器以避免熄火。同样,退后一步也能防止雄心壮志熄火。在绘画和黑客中,有些任务野心大得吓人,有些任务则令人舒适地常规。最好为那些可能会熄火的时刻存一些简单的任务。
在黑客中,这可以具体表现为积攒bug。我喜欢调试:这是黑客工作中唯一像人们想象中那样直截了当的时候。你有一个完全受限的问题,所要做的就是解决它。你的程序本应做x,却做了y。哪里有错?你知道最终你会赢。这就像刷墙一样放松。
The example of painting can teach us not only how to manage our own work, but how to work together. A lot of the great art of the past is the work of multiple hands, though there may only be one name on the wall next to it in the museum. Leonardo was an apprentice in the workshop of Verrocchio and painted one of the angels in his Baptism of Christ. This sort of thing was the rule, not the exception. Michelangelo was considered especially dedicated for insisting on painting all the figures on the ceiling of the Sistine Chapel himself.
As far as I know, when painters worked together on a painting, they never worked on the same parts. It was common for the master to paint the principal figures and for assistants to paint the others and the background. But you never had one guy painting over the work of another.
I think this is the right model for collaboration in software too. Don't push it too far. When a piece of code is being hacked by three or four different people, no one of whom really owns it, it will end up being like a common-room. It will tend to feel bleak and abandoned, and accumulate cruft. The right way to collaborate, I think, is to divide projects into sharply defined modules, each with a definite owner, and with interfaces between them that are as carefully designed and, if possible, as articulated as programming languages.
绘画的例子不仅能教我们如何管理自己的工作,还能教我们如何一起工作。过去许多伟大的艺术作品是多人合作的成果,尽管博物馆里旁边墙上可能只有一个名字。达芬奇曾是韦罗基奥工作室的学徒,并在他的《基督受洗》中画了一个天使。这种事情是常态,而不是例外。米开朗基罗因为坚持亲自绘制西斯廷教堂天花板上的所有人物而被认为特别投入。
据我所知,当画家们合作创作一幅画时,他们从不画相同的部分。通常是大师绘制主要人物,助手绘制其他人以及背景。但绝不会有一个人覆盖另一个人的工作。
我认为这也是软件协作的正确模式。不要过头。当一段代码由三四个不同的人修改时,没有人真正拥有它,它最终会像一个公共休息室。它会让人感到荒凉和被遗弃,并积累脏东西。我认为正确的协作方式是将项目划分为界限清晰的模块,每个模块有明确的拥有者,模块之间的接口要精心设计,并且如果可能的话,像编程语言一样定义明确。
Like painting, most software is intended for a human audience. And so hackers, like painters, must have empathy to do really great work. You have to be able to see things from the user's point of view.
When I was a kid I was always being told to look at things from someone else's point of view. What this always meant in practice was to do what someone else wanted, instead of what I wanted. This of course gave empathy a bad name, and I made a point of not cultivating it.
Boy, was I wrong. It turns out that looking at things from other people's point of view is practically the secret of success. It doesn't necessarily mean being self-sacrificing. Far from it. Understanding how someone else sees things doesn't imply that you'll act in his interest; in some situations-- in war, for example-- you want to do exactly the opposite.
Most makers make things for a human audience. And to engage an audience you have to understand what they need. Nearly all the greatest paintings are paintings of people, for example, because people are what people are interested in.
Empathy is probably the single most important difference between a good hacker and a great one. Some hackers are quite smart, but when it comes to empathy are practically solipsists. It's hard for such people to design great software, because they can't see things from the user's point of view.
One way to tell how good people are at empathy is to watch them explain a technical question to someone without a technical background. We probably all know people who, though otherwise smart, are just comically bad at this. If someone asks them at a dinner party what a programming language is, they'll say something like ``Oh, a high-level language is what the compiler uses as input to generate object code.'' High-level language? Compiler? Object code? Someone who doesn't know what a programming language is obviously doesn't know what these things are, either.
Part of what software has to do is explain itself. So to write good software you have to understand how little users understand. They're going to walk up to the software with no preparation, and it had better do what they guess it will, because they're not going to read the manual. The best system I've ever seen in this respect was the original Macintosh, in 1985. It did what software almost never does: it just worked.
和绘画一样,大多数软件是为人类受众设计的。因此,黑客和画家一样,必须拥有共情才能做出真正伟大的作品。你必须能够从用户的角度看问题。
当我还是个孩子时,总是被告知要从别人的角度看问题。这在实践中总是意味着做别人想做的事,而不是我想做的事。这当然给共情带来了坏名声,我特意不去培养它。
天哪,我错了。原来从别人的角度看问题几乎是成功的秘诀。这并不一定意味着自我牺牲。远非如此。理解别人如何看待事物并不意味着你会为他的利益行事;在某些情况下——例如在战争中——你恰恰想反着做。
大多数创造者为人做东西。而要吸引受众,你必须理解他们的需求。例如,几乎所有最伟大的绘画都是人物画,因为人们感兴趣的是人。
共情可能是优秀黑客和伟大黑客之间唯一最重要的区别。有些黑客非常聪明,但说到共情,简直像唯我论者。这样的人很难设计出伟大的软件,因为他们无法从用户的角度看问题。
判断一个人有多善于共情的一个方法是观察他们如何向没有技术背景的人解释技术问题。我们大概都知道一些人,尽管在其他方面很聪明,但在这一点上却可笑地糟糕。如果有人在晚宴上问他们什么是编程语言,他们会说:“哦,高级语言是编译器用来生成目标代码的输入。”高级语言?编译器?目标代码?一个连编程语言是什么都不知道的人显然也不懂这些是什么。
软件的一部分工作就是解释自己。因此,要写出好软件,你必须理解用户的理解有多么少。他们会在没有任何准备的情况下接触软件,而软件最好能按照他们猜测的方式运作,因为他们不会去读手册。在这方面我见过的最好的系统是1985年的原始Macintosh。它做到了软件几乎从未做到的事:它只管用。
Source code, too, should explain itself. If I could get people to remember just one quote about programming, it would be the one at the beginning of Structure and Interpretation of Computer Programs.
Programs should be written for people to read, and only incidentally for machines to execute.
You need to have empathy not just for your users, but for your readers. It's in your interest, because you'll be one of them. Many a hacker has written a program only to find on returning to it six months later that he has no idea how it works. I know several people who've sworn off Perl after such experiences.
源代码也应该自我解释。如果我能让人们只记住一句关于编程的话,那就是《计算机程序的构造和解释》开篇的那句:
“程序应该写给人阅读,只是顺便让机器执行。”
你不仅要对用户有共情,还要对读者有共情。这符合你自己的利益,因为你也会成为读者之一。很多黑客写过程序,六个月后再回来看,却完全不知道它是如何工作的。我认识几个经历过这种事的人,之后他们发誓再也不碰Perl了。
Lack of empathy is associated with intelligence, to the point that there is even something of a fashion for it in some places. But I don't think there's any correlation. You can do well in math and the natural sciences without having to learn empathy, and people in these fields tend to be smart, so the two qualities have come to be associated. But there are plenty of dumb people who are bad at empathy too. Just listen to the people who call in with questions on talk shows. They ask whatever it is they're asking in such a roundabout way that the hosts often have to rephrase the question for them.
缺乏共情有时被与智力联系在一起,以至于在某些地方甚至成为一种风尚。但我不认为两者有任何相关性。你可以在数学和自然科学中表现出色而无需学习共情,而这些领域的人往往很聪明,所以这两种特质就被联系起来了。但也有大量不擅长共情的笨人。只要听听那些打电话进脱口秀节目提问的人就知道了。他们用绕来绕去的方式提问,主持人们经常不得不为他们重新措辞问题。
So, if hacking works like painting and writing, is it as cool? After all, you only get one life. You might as well spend it working on something great.
Unfortunately, the question is hard to answer. There is always a big time lag in prestige. It's like light from a distant star. Painting has prestige now because of great work people did five hundred years ago. At the time, no one thought these paintings were as important as we do today. It would have seemed very odd to people at the time that Federico da Montefeltro, the Duke of Urbino, would one day be known mostly as the guy with the strange nose in a painting by Piero della Francesca.
So while I admit that hacking doesn't seem as cool as painting now, we should remember that painting itself didn't seem as cool in its glory days as it does now.
What we can say with some confidence is that these are the glory days of hacking. In most fields the great work is done early on. The paintings made between 1430 and 1500 are still unsurpassed. Shakespeare appeared just as professional theater was being born, and pushed the medium so far that every playwright since has had to live in his shadow. Albrecht Durer did the same thing with engraving, and Jane Austen with the novel. Over and over we see the same pattern. A new medium appears, and people are so excited about it that they explore most of its possibilities in the first couple generations. Hacking seems to be in this phase now.
Painting was not, in Leonardo's time, as cool as his work helped make it. How cool hacking turns out to be will depend on what we can do with this new medium.
那么,如果黑客的工作方式像绘画和写作,它有这么酷吗?毕竟,你只有一次生命。你不如把它花在创造伟大的东西上。
不幸的是,这个问题很难回答。声望总是有很大的时间滞后。就像来自遥远恒星的光。绘画现在有声望,是因为五百年前的人们所做的伟大工作。在当时,没有人认为这些画有我们今天认为的那么重要。对当时的人来说,乌尔比诺公爵费德里科·达·蒙特费尔特罗有一天会主要因为皮耶罗·德拉·弗朗切斯卡画中那个奇怪的鼻子而闻名,这看起来会非常奇怪。
所以,虽然我承认黑客现在看起来没有绘画那么酷,但我们应该记住,绘画本身在其辉煌时期也没有现在看起来那么酷。
我们可以比较有把握地说,现在是黑客的黄金时代。在大多数领域,伟大的工作都是在早期完成的。1430年至1500年间创作的绘画至今仍无与伦比。莎士比亚出现在专业戏剧诞生之初,并将媒介推向了如此之远,以至于之后的每个剧作家都不得不活在他的阴影下。阿尔布雷特·丢勒对版画做了同样的事,简·奥斯汀对小说也是如此。我们一次又一次地看到同样的模式。一种新媒介出现,人们如此兴奋,以至于在前几代人就探索了它大部分的可能性。黑客现在似乎正处于这个阶段。
在达芬奇的时代,绘画并没有他的作品帮助它达到的那么酷。黑客最终会变得多酷,将取决于我们能用这种新媒介做些什么。