公众号请关注ElseF,ElseF(Else Figure),是一个专注于「分享」国内外高质量的科技类文章和新闻的自媒体。维护者主要来自国内外大型互联网公司和创业公司,主要专注于与互联网相关的精彩内容。
微信公众号
编程这么多年,相信大家对面向对象编程OOP并不陌生,尤其是Java语言的使用者。你对OOP的特性了解吗?它们带来了什么好处呢?今天向大家推荐一些国外大神们对OOP的评价——负面评价(按时间顺序排列)。欢迎大家在留言区发表自己的观点进行讨论。
Edsger W. Dijkstra (1989)
“TUG LINES,” Issue 32, August 1989
“Object oriented programs are offered as alternatives to correct ones” and “Object-oriented programming is an exceptionally bad idea which could only have originated in California.”
F君:Dijkstra这个名字始终是我求学生涯的阴影,另外California好像是他的阴影?
Alan Kay (1997)
The Computer Revolution hasn’t happened yet
“I invented the term object-oriented, and I can tell you I did not have C++ in mind.” and “Java and C++ make you think that the new ideas are like the old ones. Java is the most distressing thing to happen to computing since MS-DOS.” (proof)
F君:Alan还是很诚实的一个人,自黑的同时不忘带上MS-DOS。
Paul Graham (2003)
The Hundred-Year Language
“Object-oriented programming offers a sustainable way to write spaghetti code.”
F君注:看完这句话我愣是有点饿呢。
Richard Mansfield (2005)
Has OOP Failed?
“With OOP-inflected programming languages, computer software becomes more verbose, less readable, less descriptive, and harder to modify and maintain.”
F君注:OOP-inflected啧啧,这是多看不起OOP啊!
Eric Raymond (2005)
The Art of UNIX Programming
“The OO design concept initially proved valuable in the design of graphics systems, graphical user interfaces, and certain kinds of simulation. To the surprise and gradual disillusionment of many, it has proven difficult to demonstrate significant benefits of OO outside those areas.”
F君注:Eric的评价算是很中肯了。
Jeff Atwood (2007)
Your Code: OOP or POO?
“OO seems to bring at least as many problems to the table as it solves.”
F君注:他也是个纠结的人儿~
Linus Torvalds (2007)
“C++ is a horrible language. … C++ leads to really, really bad design choices. … In other words, the only way to do good, efficient, and system-level and portable C++ ends up to limit yourself to all the things that are basically available in C. And limiting your project to C means that people don’t screw that up, and also means that you get a lot of programmers that do actually understand low-level issues and don’t screw things up with any idiotic “object model” crap.”
F君注:Linus一向以敢说脏话而出名,没有他不敢diss的,谁让他是Linus呢?
Oscar Nierstrasz (2010)
Ten Things I Hate About Object-Oriented Programming
“OOP is about taming complexity through modeling, but we have not mastered this yet, possibly because we have difficulty distinguishing real and accidental complexity.”
F君注:real和accidental complexity,这句话还真的是幽默中带点深沉呢。
Rich Hickey (2010)
SE Radio, Episode 158
“I think that large objected-oriented programs struggle with increasing complexity as you build this large object graph of mutable objects. You know, trying to understand and keep in your mind what will happen when you call a method and what will the side effects be.”
F君注:随着工程变得愈加复杂,需要面对的问题就会变得更多,尤其是在OOP程序里,可能不小心就“牵一发而动全身”。
Eric Allman (2011)
Programming Isn’t Fun Any More
“I used to be enamored of object-oriented programming. I’m now finding myself leaning toward believing that it is a plot designed to destroy joy. The methodology looks clean and elegant at first, but when you actually get into real programs they rapidly turn into horrid messes.”
F君注:简单的例子看起来总是那么优雅和美好,但是真正融入到具体业务的冗长逻辑中时往往又是绝大多数人回归现实的时候。
Joe Armstrong (2011)
Why OO Sucks
“Objects bind functions and data structures together in indivisible units. I think this is a fundamental error since functions and data structures belong in totally different worlds.”
F君注:工程师都是有洁癖的,不光是写代码本身,还包括写什么样的代码,嗯嗯。
Rob Pike (2012)
“Object-oriented programming, whose essence is nothing more than programming using data with associated behaviors, is a powerful idea. It truly is. But it’s not always the best idea. … Sometimes data is just data and functions are just functions.”
F君注:data是data,function是function,data with associal behaviors就是data+function,即OOP了。嗯...sometimes亮了。
John Barker (2013)
All evidence points to OOP being bullshit
“What OOP introduces are abstractions that attempt to improve code sharing and security. In many ways, it is still essentially procedural code.”
F君注:并不是100%面向对象,难免会有面向过程的痕迹。
Lawrence Krubner (2014)
Object Oriented Programming is an expensive disaster which must end
“We now know that OOP is an experiment that failed. It is time to move on. It is time that we, as a community, admit that this idea has failed us, and we must give up on it.”
F君注:experiment that failed这个结论是咋来的?
Asaf Shelly (2015)
Flaws of Object Oriented Modeling
“Reading an object oriented code you can’t see the big picture and it is often impossible to review all the small functions that call the one function that you modified.”
最后,F君认为Asaf Shelly说出了很多人的痛点,笔者每次陷入在用OOP过度设计的代码中匍匐前进的时候都感到深深的绝望,想看个big picture真的很难啊!