[閒聊] 轉貼一篇評論 物件導向 的國外文章

看板C_and_CPP (C/C++)作者 (purpose)時間15年前 (2010/09/29 11:56), 編輯推噓7(7021)
留言28則, 9人參與, 最新討論串1/1
原文網址: http://coolshell.cn/articles/3036.html 我轉成繁體中文後,節錄前半篇內容於下。 -- 今天在網上看到網頁叫「Object Orientation Isa Hoax」——物件導向是一個騙局, http://c2.com/cgi/wiki?ObjectOrientationIsaHoax 標題很有煽動性 (註:該網站上還有一個網頁叫Object Orientation Is Dead), http://c2.com/cgi/wiki?ObjectOrientationIsDead 好吧,打開看看上面有些什麼,發現這個網頁是在收集一些關於 「物件導向的反動言論」,沒想到的是,很多言論出自很多大師之口。 比如:Alexander Stepanov 和 Bjarne Stroustrup。 這些言論挺有意思的,所以,我摘兩段在下面: 第一段是Alexander Stepanov的 (不要告訴我你不知道這個人,STL之父,關於他的故事,可以到這裡看看)。 http://www.techcn.com.cn/index.php?doc-view-131345.html 他N年前作過一段採訪,原文在這裡 http://www.stlport.org/resources/StepanovUSA.html (我非常建議大家去讀一下這篇採訪,相當過癮),譯文在這裡 http://dev.csdn.net/htmls/11/11440.html (不過有地方把原意都譯反了,我重譯了一下),其中有一個問答被上述的那個 物件導向反動言論的網頁收錄了: Question: I think STL and Generic Programming mark a definite departure from the common C++ programming style, which I find is almost completely derived from SmallTalk. Do you agree? 提問: 我認為STL和泛型程式設計標誌著非同一般的C++程式設計風格,而這種風格幾乎完全是從 SmallTalk延伸過來的。你同意嗎? Answer: Yes. STL is not object oriented. I think that object orientedness is almost as much of a hoax as Artificial Intelligence. I have yet to see an interesting piece of code that comes from these OO people. In a sense, I am unfair to AI: I learned a lot of stuff from the MIT AI Lab crowd, they have done some really fundamental work: Bill Gosper's Hakmem is one of the best things for a programmer to read. AI might not have had a serious foundation, but it produced Gosper and Stallman (Emacs), Moses (Macsyma) and Sussman (Scheme, together with Guy Steele). I find OOP technically unsound. It attempts to decompose the world in terms of interfaces that vary on a single type. To deal with the real problems you need multisorted algebras - families of interfaces that span multiple types. I find OOP philosophically unsound. It claims that everything is an object. Even if it is true it is not very interesting - saying that everything is an object is saying nothing at all. I find OOP methodologically wrong. It starts with classes. It is as if mathematicians would start with axioms. You do not start with axioms - you start with proofs. Only when you have found a bunch of related proofs, can you come up with axioms. You end with axioms. The same thing is true in programming: you have to start with interesting algorithms. Only when you understand them well, can you come up with an interface that will let them work. 回答: 是的。STL不是物件導向的。我認為物件導向和人工智慧差不多,都是個騙局。 我至今仍然沒有從那些寫OO的人那裡看到一丁點有意思的程式碼。 從某種意義上來說,我這麼說對人工智慧(AI)並不公平: 因為我聽說過很多 MIT AI 實驗室裡一幫人搞出來的東西, (I learned a lot of stuff from the MIT AI Lab crowd,) 而且他們的確直正幹了一些基礎性的工作: (they have done some really fundamental work:) Bill Gosper 的 Hakmem 是程式設計師最好的讀物之一。 AI 或許沒有一個實實在在的基礎, (AI might not have had a serious foundation,) 但它造就了 Gosper 和 Stallman(Emacs),Moses(Macsyma)和 Sussman (Scheme, 和 Guy Steele 一起)。 * 我發現 OOP 在技術上是荒謬的,它企圖把事物按照不同單個型態的介面來解構, 為了處理實際問題,你需要多種代數方法——橫跨多種型態的介面族; (I find OOP technically unsound. It attempts to decompose the world in terms of interfaces that vary on a single type. To deal with the real problems you need multisorted algebras - families of interfaces that span multiple types.) * 我發現 OOP 在哲學上是荒謬的,它聲稱一切都是物件。即使這是真的也不是 很有趣——因為說一切都是物件跟什麼都沒說一樣; * 我發現 OOP 的方法論是錯誤的,它從類別開始,就好像數學要從公理開始一樣。 你不從公理開始,你就要從證明開始。直到你找到了一大堆相關證據後你才能 歸納出公理 (axioms),然後以公理結束。在程式設計方面存在著同樣的事實: 你要從有趣的演算法開始。只有很好地理解了演算法,你才有可能提煉出介面 以讓其工作。 下面,我們再來看 C++ 的發明者 Bjarne Stroustrup,在1998年 IEEE 採訪時的一段話 (全篇見這裡), http://www2.research.att.com/~bs/ieee_interview.html 下面是其中的幾段話:(我的翻譯如下) .....後半篇略,有興趣可至原文網址觀看。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 124.8.130.150

09/29 12:45, , 1F
學了靜態多型就覺得動態多型在設計上很麻煩, 不過其實
09/29 12:45, 1F

09/29 12:46, , 2F
還有更高於code之上的概念不用物件導向沒辦法傳遞的,
09/29 12:46, 2F

09/29 12:46, , 3F
所以才是要各取所需才是 :)
09/29 12:46, 3F

09/29 12:47, , 4F
09/29 12:47, 4F

09/29 12:55, , 5F
interesting
09/29 12:55, 5F

09/29 13:00, , 6F
我覺得 Alexander Stepanov 還...蠻嗆的
09/29 13:00, 6F

09/29 13:36, , 7F
時代是 go (其實就是 auto concept map) XD
09/29 13:36, 7F

09/29 13:36, , 8F
duck typing 的開發, static type 的效能 qq
09/29 13:36, 8F

09/29 13:37, , 9F
還有在 c++ 裡面地獄一般的編譯時間 orz
09/29 13:37, 9F

09/29 13:57, , 10F
天堂一般的執行時間 \(^▽^)/
09/29 13:57, 10F

09/29 14:47, , 11F
C++ 程式裡本來就不能只有純 OO,我只在高階區寫 60% 左右
09/29 14:47, 11F

09/29 14:48, , 12F
的 OO。整個 C++ 程式全部寫 OO,第一個會被我笑死。
09/29 14:48, 12F

09/29 14:49, , 13F
不過因為常有人 OO 的成分低於 1%,所以常看到我對這類人
09/29 14:49, 13F

09/29 14:49, , 14F
強調 OO 的重要性,造成有些人產生我推純 OO 的錯覺 XD
09/29 14:49, 14F

09/29 15:19, , 15F
蠻好奇的所謂的高階區是指什麼?還有為什麼只有60%,這比率不
09/29 15:19, 15F

09/29 15:19, , 16F
能再高的原因是?
09/29 15:19, 16F

09/29 15:25, , 17F
哇哈哈 java sux
09/29 15:25, 17F

09/29 15:35, , 18F
就是比較偏向表層的東西,譬如 UI 層的臨接處。
09/29 15:35, 18F

09/29 15:35, , 19F
或是不同子系統間的銜接點附近。
09/29 15:35, 19F

09/29 15:36, , 20F
因為中下層比較偏像 GP,跟 template 銜接不可能純 OO,
09/29 15:36, 20F

09/29 15:36, , 21F
所以要讓 OO 破 60% 很難。template 這東西有感染使用它的
09/29 15:36, 21F

09/29 15:37, , 22F
code 的特性,有點像是 virus,寫過就會知道。
09/29 15:37, 22F

09/29 17:05, , 23F
同一樓上
09/29 17:05, 23F

09/29 17:15, , 24F
09/29 17:15, 24F

09/29 17:15, , 25F
我也很討厭用STL這類的東西
09/29 17:15, 25F

09/29 17:26, , 26F
^偏向 (修 15:36 第一行那個錯字)
09/29 17:26, 26F

09/30 01:53, , 27F
囧 那... Ruby該如何自處勒? 我整個語言都是騙局 XXD
09/30 01:53, 27F

09/30 23:31, , 28F
原來這個紅寶石是騙人的...(大誤XD)
09/30 23:31, 28F
文章代碼(AID): #1CehZbqn (C_and_CPP)
文章代碼(AID): #1CehZbqn (C_and_CPP)