Wednesday, December 17, 2008

Linus on C++

Reading this was pure joy!

http://lwn.net/Articles/249460/

"C++ leads to really really bad design choices. You invariably start using the "nice" library features of the language like STL and Boost and other total and utter crap, that may "help" you program, but causes:

- infinite amounts of pain when they don't work (and anybody who tells me that STL and especially Boost are stable and portable is just so full of BS that it's not even funny)

- inefficient abstracted programming models where two years down the road you notice that some abstraction wasn't very efficient, but now all your code depends on all the nice object models around it, and you cannot fix it without rewriting your app."

Yes... Yes. Yes!!! Finally. Somebody said it. Linus is now my hero!

Seriously, if you use C++ to its full extent - and look at inane amount of crap they put in C++0x (http://en.wikipedia.org/wiki/C%2B%2B0x) - lambdas! concepts! alternative function syntax (yes, check THAT one out!), built-in iterators! - why not use C# or Java instead? Equally slow (*), at least they are well designed.

What used to be a very much WYSIWYG language with a very well defined purpose (speed and closeness to hardware) is now becoming a random subset of everything from JavaScript to Haskell, whether it makes sense to pack it in one place or not.

(*) STL semantics encourages runaway number of memory allocations which is very similar to C# and Java. The difference is that both Java and C# have memory systems that are designed for this purpose - the cost of object creation is very, very low - whereas in C++ it is anything but. (http://1-800-magic.blogspot.com/2007/11/guerilla-guide-to-native-memory.html)

6 comments:

Sanik said...

Man, you've got a really old post. It's like your grandma socks exposed :-)
Btw, Linus is not god.

NS said...

Ah, one of my favorites.

C++ is not a bad language. It just has a lot of lousy users.

Obviously, it's hard to disagree on STL - if you want to write Java, write Java.

C++ is C with classes, when used as such it is efficient and effective, and there's nothing wrong with it.

Anonymous said...

There is a comprehensive C++ critic by Yossi Kreinin with tons of examples why C++ is bad.

http://yosefk.com/c++fqa/index.html

He also has a blog and in this post he writes that after years of C++ he starts to prefer plain C

http://www.yosefk.com/blog/oo-c-is-passable.html

Mikhail Poda

Jim Lyon said...

Beware of people who use only one bit to measure the quality of anything.

BadTux said...

Linus has been saying these sorts of things for over a decade now so I don't know about the "finally said it" bit, I remember him nattering on about idiocies in C++, hmm, must have been '96 or so when some durnfool suggested that it'd be really cool to write Linux in an object-oriented language like, err, C++. (I hesitate to name the durnfool who made that suggestion, err, ah. Yeah). Anyhow. My complaint is that Linus seems willing to throw the baby out with the bathwater.

Yeah, C++'s templates etc. are atrocities. One of my engineers proposed that the next version of one of our core apps be written in C++, and showed me some prototype code, and I pointed out that his overuse of templates basically resulted in an entire class being compiled multiple times with different types filled in for various parameters and therefore bloated up his code to roughly the same size as the Titanic. He had absolutely no idea of how templates were implemented by our C++ compiler or why overuse of the STL would result in code roughly the size and speed of a dead whale.

But that's not Linus's core beef. His core beef seems to be that object-oriented programming is evil by definition because you might get the object hierarchy wrong and therefore hard-code an inefficiency into the core architecture of the program that cannot be fixed without re-writing the entire program.

The problem is that you can do this with *any* architecture, whether object-oriented or not. "Object-oriented programming" is by its nature an abstraction on top of namespaces and structs with a list of functions associated with particular structs, rather than being something that is fundamentally different from non-object-oriented programming. Furthermore, those of us who've been doing object-oriented programming for many years a) have the experience to properly architect the object hierarchy in the first place, and b) have the experience to set up our objects so that they can be easily re-factored as we learn new things about the application set (i.e., we design for change rather than designing to meet only a specific fixed specification). For example, last week my CTO and VP of Engineering called me into a meeting and asked for a fairly major feature to be added to our new product and apologized for causing the need for a fairly major re-write at this late stage of the project. I said "No problem, I can think of three different ways that feature can fit into our object hierarchy with very little modification of the existing code, just new objects in the interstices." Because the architecture was designed with room for unknown concepts to be added in without major disruption of the basic architecture of the application. My engineers grumbled a bit over some of the things that I had them doing, but there was a reason for all of what I did, and now they're seeing it.

So anyhow, good architecture is good architecture, objects or no, and the same with bad architecture. Seems to me that Linus is confusing bad architecture with objects. Which maybe is something excusable if he's thinking about C++ objects, templates, and the STL/Boost, but he seemed to go beyond C++ and blame object-oriented programming as a whole as the cause of bad architecture. And I'm not sure that's defensible.

tiger said...

成人論壇,080聊天室,080苗栗人,免費a片,視訊美女,視訊做愛,免費視訊,伊莉討論區,sogo論壇,台灣論壇,plus論壇,維克斯論壇,情色論壇,性感影片,正妹,走光,色遊戲,情色自拍,kk俱樂部,好玩遊戲,免費遊戲,貼圖區,好玩遊戲區,中部人聊天室,情色視訊聊天室,聊天室ut,成人電影,成人遊戲,成人文學,免費成人影片,成人光碟,情色遊戲,情色a片,情色網,性愛自拍,美女寫真,亂倫,戀愛ING,免費視訊聊天,視訊聊天,成人短片,美女交友,美女遊戲,18禁,三級片,自拍,後宮電影院,85cc,免費影片,線上遊戲,色情遊戲,日本a片,美女,成人圖片區,avdvd,色情遊戲,情色貼圖,女優,偷拍,正妹牆