Paul Graham: Essays 2024年11月25日
Why Arc Isn't Especially Object-Oriented
index_new5.html
../../../zaker_core/zaker_tpl_static/wap/tpl_guoji1.html

 

本文探讨了面向对象编程的流行及其背后的原因,作者认为面向对象编程在某些情况下是一种有用的技术,但并非所有程序都必须采用这种方式。作者分析了人们喜欢面向对象编程的五个原因,其中三个半是负面的,例如它在大型公司中流行是因为它适合大型团队的开发方式,以及它可以创造出大量看似有用的工作。作者也指出,面向对象编程的抽象概念并非适用于所有类型的程序,并分享了自己从未使用过 Common Lisp 的对象系统的经验。文章最后提醒,在设计语言时,不要盲目地加入自己从未使用过的特性,因为这可能比只基于自身经验设计语言更危险。

🤔 **面向对象编程在某些情况下有用,但并非万能:**作者认为面向对象编程是一种有用的技术,但在某些情况下,它并非必须。它并非适用于所有程序,程序员不应该被强迫将所有程序都表达成新类型的定义。

🏢 **大型公司青睐面向对象编程,因为它适合大型团队协作:**在大型公司中,软件通常由大量(且经常变化)的中等水平的程序员团队编写。面向对象编程为这些程序员强加了一种纪律,防止任何一个人造成过大的损害,但代价是生成的代码臃肿且重复。

👷 **面向对象编程能创造出大量看似有用的工作:**面向对象编程可以让你在源代码中加入大量的支架代码,这对于那些喜欢在代码中加入大量注释和格式的程序员来说非常有吸引力。

💡 **面向对象抽象并非适用于所有程序:**作者认为面向对象抽象概念适合特定类型的程序,例如模拟和 CAD 系统,但并非所有程序都适用。作者举例说明,自己从未使用过 Common Lisp 的对象系统,因为在其他语言中可以用其他方法实现相同的功能。

⚠️ **设计语言时,不要盲目地加入自己从未使用过的特性:**作者认为,在设计语言时,不要因为认为某项特性是好主意就将其加入其中,这可能比只基于自身经验设计语言更危险。

There is a kind of mania for object-oriented programming at the moment, butsome of the smartest programmers I know are some of the least excited about it.My own feeling is that object-orientedprogramming is a useful technique in somecases, but it isn't something that has to pervade every program youwrite. You should be able to define new types,but you shouldn't have to express every program as thedefinition 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 theselimitations. (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 ofmediocre programmers. Object-oriented programming imposes adiscipline on these programmers that prevents any one of themfrom doing too much damage. The price is that the resultingcode is bloated with protocols and full of duplication. This is not too high a price for big companies, because theirsoftware is probably going to be bloated and full of duplication anyway. Object-orientedprogramming generates a lot of what looks like work.Back in the days of fanfold, there was a type of programmer whowould only put five or ten lines of code on a page, precededby twenty lines of elaborately formatted comments. Object-oriented programming is like crack for these people: it letsyou incorporate all this scaffolding right into your sourcecode. Something that a Lisp hacker might handle by pushinga symbol onto a list becomes a whole file of classes andmethods. 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 canbe extended by users. Well, maybe. Or maybe you can doeven better by offering the sub-conceptsof 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 domainsof certain specific kinds of programs, like simulations and CADsystems. I personally have never needed object-oriented abstractions.Common Lisp has an enormously powerful object system and I'venever used it once. 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, butI have never had to use CLOS.Maybe I'm just stupid, or have worked on some limited subsetof applications. There is a danger in designing a languagebased on one's own experience of programming. But it seemsmore dangerous to put stuff in that you've never needed because it's thought to be a good idea.

Fish AI Reader

Fish AI Reader

AI辅助创作,多种专业模板,深度分析,高质量内容生成。从观点提取到深度思考,FishAI为您提供全方位的创作支持。新版本引入自定义参数,让您的创作更加个性化和精准。

FishAI

FishAI

鱼阅,AI 时代的下一个智能信息助手,助你摆脱信息焦虑

联系邮箱 441953276@qq.com

相关标签

面向对象编程 程序设计 软件开发 Common Lisp 编程语言
相关文章