Friday, June 11, 2010

C vs. C++ for Linux Kernel Development

Linus Torvalds:

One of the absolute worst features of C++ is how it makes a lot of things so context-dependent—which just means that when you look at the code, a local view simply seldom gives enough context to know what is going on.

And:

There’s no “debugger” in communication. There is no IDE that helps figure out what’s going on. There is no syntax highlighting etc.

There are just e-mails with patches and suggestions flying around. There’s no room for special tools—if you as a human cannot see what the code does from the change, it’s a problem. And you usually see about three lines of context around the code.

In this situation with hundreds or thousands of developers, primitive tools, and a huge code base, it makes more sense to optimize for clarity than conciseness or abstraction power.

12 Comments RSS · Twitter


The first quote needs to be read in context to make sense. The second sentence in his paragraph is actually necessary for the correct sentiment to come across:

And there is a very strong "culture" of C (and UNIX, for
that matter). And this is also where it's so important for
the language to be simple and unambiguous.
One of the
absolute worst features of C++ is how it makes a
lot of things so context-dependent - which just means
that when you look at the code, a local view simply seldom
gives enough context to know what is going on.

Without that sentence, it sounds like he's railing against instance variables, which didn't make any sense.


My interpretation after reading the whole thread was that Linus was actually putting forward his view that C++ is not good for anything, much less kernel development. In this view, of course, he is arguably full of crap, but for kernel development I can see his point.


Karl von L.

Eric: I don't know, the C++ FQA, combined with my own experience with the language, has helped convince me that C++ is one of the worst programming languages foisted upon the world. I recommend taking at least a cursory look at it.


@Zabba I thought that was sort of implied, but in any case I certainly recommend reading the complete posts.

@Eric Not good for anything is perhaps pushing it, but I think he makes a good point that for both higher and lower level work there are better choices.


And I was thinking that I`m the only one with the same observation. I still foun it very hard to comprehend when I look at the code.


Adam Marchetti

"I still found it very hard to comprehend when I look at the code."

I just think C++ is ugly, period. It may be faster, easier, safer... but I don't want to get sick looking at code. Namespaces and long, complicated classes can do that to you. C# is even worse... .NET is probably the ugliest baby to come out of MS labs.

I only really use Python for OOP. It is one of the few languages to make it look nice.


Ugly is just the right word.


C++ is ugly? i did not know that code can be attractive, it's just code.
C++ is probably 1 of the most powerful languages, next to C.


C is a wonderfull language, in my opinion.
I am not showing my love but telling the truth. C++ is just an ant if compared to C.


I am a bioinformatics guy and using perl for my bread and butter. We use Perl + Mouse (not MOOSE) + NGINX for most of our tasks. Whenever there is a performance issue, we use perl inline module. (which helps us to write c code).

I will live with perl for next 20 years as it is the best.

I think "C" is better than C++ because one can easily debug the code in C. Currently, I am learning openMP with C because I found functional languages a nightmare to learn. (But FP langs are good and even have decent performance)

My 2 rupees.


I have programmed a variety of programs in C++ for more than 10 years and I think you all are mistaken, C++ is not THAT hard to debug, C++ classes are only complicated when the writer bunches everything up like C code and doesn't make use of polymorphism. I don't know about developing a kernel's low level systems with it but certainly higher features would benefit from the robust & safe code that C++ can provide in the fingers of the right typer.


C++ is not for everyone, only those who know how to work with different
abstraction mechanisms could handle the power of C++.If you fail to do that,
that means you can't have the good balance between performance and flexibility
with the help of C++,this imply you should go back to C because C++ is not suit
for you.

Leave a Comment