A response to Linus Torvalds on C++ (2007)
warp.povusers.org
warp.povusers.org
i'm reading a bunch of C++ lately and i have to say i like it, i like it a lot. it's something i may have to dive into and actually learn.
some of this is due, i think, to solid standards coming in, but also a lot of growth on my part as a coder.
plenty of things are done better in OOP than not, where re-use through inheritance, design by composition, and modularity are needed and well executed.
my bigotry against C++ has ended.
https://code.google.com/p/v8/source/browse/branches/3.0/src/...
and some of it is back.
While I am at it, it is my opinion that bad C++ programming style is much worse than bad C programming styles.
For example http://i.imgur.com/xtohcJH.jpg CUDA programmers would understand.
Sad to say that a lot of people's bias against c++ is rooted in their experience with it 10-20 years ago. Poor compilers, poor stdlibs, poor portability, etc. If that is you, I would encourage you to check out what modern c++ is like. C++11 fixes a bunch of things, c++14 will fix some things that the committee missed. Yeah, c++ is big and complicated, but so is every language, even C. Yeah the C core language is small, but any large project starts either rolling their own library for data structures, algorithms, string processing, etc, or linking in behemoths like glib. C++ just comes with a lot of the basics included, and learning the best practices and modern idioms of using the language isn't that bad. Consider:
unique_ptr<foo> bar(); // c++
foo* bar(); // c.
The C++ version conveys way more information (and is almost impossible to screw up its use accidentally), without the need for comments, and compiles to the same code. This is just one example, but they abound.Recently I found this: http://yosefk.com/c++fqa/
It explains most of the reasons I disliked C++ and, if you've ever used it, you might recognise the issues dealt with.
It looks and feels exactly like the kind of defensive article you would expect from a insecure C++ programmer. Maybe he should have just tweeted "Everything Linus said is wrong! WRONG!" instead.
The other thing is about class-based languages. They are great for implementing hierarchies of concepts, like GUI toolkits and a few other things. But, they do promote bulk and it's not rare to have a lot of object thrashing. That's not specific to C++, though.
Third, system-level library are often exclusively exposed via C libraries. Core things like BSD sockets, POSIX threads, memory management. Yes, you can wrap them in C++ or use C++-based libraries that add sugar on top, but more often than not you end up wondering "why don't I use the system APIs directly?" You often feel like you have to jump through unnecessary hoops when you don't.
Just my opinion, of course. I would use C++ if there was a good reason for any particular job. It is just not my natural inclination.
[1] http://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html [2] http://ohse.de/uwe/articles/gcc-attributes.html#func-pure
Also why would C be better otherwise?
It is reasonable to speculate that C++ is more popular with beginner programmers than C, and that this may significantly affect the characteristics of a software project developed by a big team or community, as opposed a single particular programmer.
It is also reasonable to assume that trovalds speaks out of his experience and doesn't merely speculate.
As for me, his observation perfectly matches my personal experience.
I think it's clear that Linus isn't talking about the language as the syntax and semantics that get accepted by a compiler, but in a broader sense, relevant to the Real World, which includes a social context.
There's a culture and social context around a language, that includes things such as idioms, best practices, libraries, learning material, etc, which are fundamental to the practice of programming in it.
Apple uses C++ in their kernel in a nice way, they don't use virtual methods and templates.
I agree totally that C++ looks good and all, and that there might be bright sides to it. But to me, it is not as discernible as C at least. And I do enjoy programming in C, I need to feel I am in control, and C gives me that.
He claims that C was designed by committee, which I can only assume is a defensive projection meant to hide that C++ was designed and is maintained by committee. He points out mplayer as an example of C code that is supposed to be good but is actually bad, which is a low blow. (mplayer's code quality has always been awful and this is well-known in the community.)
The railing against C++ object models being bad is similarly defensive, and I get the feeling that the author is deliberately trying to make people forget that pImpls ever happen.
C++ is an incredibly obtuse language, full of so many misfeatures and fancy whirligigs that it's difficult to be certain that even repeated reads through a file are giving you the correct impression of structure and flow.