← Paul Graham

Why Arc Isn't Especially Object-Oriented

为什么 Arc 不是特别面向对象
 ·  Paul Graham  ·  原文

There is a kind of mania for object-oriented programming at the moment, but some of the smartest programmers I know are some of the least excited about it.

目前有一种对面向对象编程的狂热,但我认识的一些最聪明的程序员却对此最不感兴趣。

My own feeling is that object-oriented programming is a useful technique in some cases, but it isn't something that has to pervade every program you write.

我自己的感觉是,面向对象编程在某些情况下是一种有用的技术,但它并不是必须渗透到您编写的每个程序中。

You should be able to define new types, but you shouldn't have to express every program as the

您应该能够定义新类型,但不必将每个程序表示为

definition of new types.

新类型的定义。

I think there are five reasons people like object-oriented programming, and three and a half of them are bad: Object-oriented programming is exciting if you have a statically-typed language without lexical closures or macros.

我认为人们喜欢面向对象编程有五个原因,其中三个半是不好的: 如果你有一种没有词法闭包或宏的静态类型语言,那么面向对象编程是令人兴奋的。

To some degree, it offers a way around these limitations.

在某种程度上,它提供了一种绕过这些限制的方法。

(See Greenspun's Tenth Rule .) Object-oriented programming is popular in big companies, because it suits the way they write software.

(参见格林斯潘的第十条规则。)面向对象编程在大公司中很流行,因为它适合他们编写软件的方式。

At big companies,

在大公司,

software tends to be written by large (and frequently changing) teams of mediocre programmers.

软件往往是由大型(且经常变化的)平庸程序员团队编写的。

Object-oriented programming imposes a discipline on these programmers that prevents any one of them from doing too much damage.

面向对象编程对这些程序员施加了一种纪律,以防止他们中的任何一个人造成太大的损害。

The price is that the resulting code is bloated with protocols and full of duplication.

代价是生成的代码因协议而变得臃肿且充满重复。

This is not too high a price for big companies, because their software is probably going to be bloated and full of

这对于大公司来说并不算太高的价格,因为他们的软件很可能会变得臃肿且充满了

duplication anyway.

无论如何都是重复的。

Object-oriented programming generates a lot of what looks like work.

面向对象编程产生了很多看起来像工作的东西。

Back in the days of fanfold, there was a type of programmer who would only put five or ten lines of code on a page, preceded by twenty lines of elaborately formatted comments.

早在单页纸时代,有一种程序员只会在一页上放置五行或十行代码,然后是二十行精心格式化的注释。

Object-oriented programming is like crack for these people: it lets you incorporate all this scaffolding right into your source code.

对于这些人来说,面向对象编程就像破解:它允许您将所有这些脚手架直接合并到源代码中。

Something that a Lisp hacker might handle by pushing

Lisp 黑客可以通过推送来处理的事情

a symbol onto a list becomes a whole file of classes and methods.

列表中的符号成为类和方法的整个文件。

So it is a good tool if you want to convince yourself, or someone else, that you are doing a lot of work.

因此,如果您想说服自己或其他人您正在做很多工作,那么它是一个很好的工具。

If a language is itself an object-oriented program, it can be extended by users.

如果一种语言本身是面向对象的程序,那么它就可以由用户扩展。

Well, maybe.

嗯,也许吧。

Or maybe you can do even better by offering the sub-concepts of object-oriented programming a la carte.

或者,也许您可​​以通过按菜单提供面向对象编程的子概念来做得更好。

Overloading, for example, is not intrinsically tied to classes.

例如,重载本质上与类没有联系。

We'll see.

我们拭目以待。

Object-oriented abstractions map neatly onto the domains of certain specific kinds of programs, like simulations and CAD systems.

面向对象的抽象巧妙地映射到某些特定类型程序的领域,例如模拟和 CAD 系统。

I personally have never needed object-oriented abstractions.

我个人从来不需要面向对象的抽象。

Common Lisp has an enormously powerful object system and I've never used it once.

Common Lisp 有一个非常强大的对象系统,但我从未使用过它一次。

I've done a lot of things (e.g. making hash tables full of closures) that would have required object-oriented techniques to do in wimpier languages, but

我做了很多事情(例如,让哈希表充满闭包),这些事情需要面向对象的技术才能在较弱的语言中完成,但是

I have never had to use CLOS.

我从来没有使用过 CLOS。

Maybe I'm just stupid, or have worked on some limited subset of applications.

也许我只是愚蠢,或者只开发了一些有限的应用程序子集。

There is a danger in designing a language based on one's own experience of programming.

根据自己的编程经验来设计语言是有危险的。

But it seems more dangerous to put stuff in that you've never needed because it's thought to be a good idea.

但把你从来不需要的东西放进去似乎更危险,因为这被认为是个好主意。

中文为机器翻译,仅供参考。