http://harmful.cat-v.org/software/c++/linus
I wonder if things have changed in the decade since he penned that.
There are reasons to avoid using C++:
* The main benefit of C++ is that it has a standard library that's somewhat usable. Except you can't use standard libraries anyways in kernel code.
* Templates, particularly as they intersect with name lookup, are difficult semantics both to the compiler and the user. Until a decade ago, using templates meant more or less playing roulette as to which compilers could handle it correctly.
* RTTI and exceptions are broken features. It has more or less been accepted that these features are optional in C++.
* The famous saying goes "there's a safe subset to C++, but no one agrees what that subset is." That's still more or less true today.
The main advantage of C++ is that it gets you RAII (which makes dealing with errors much easier, since you're less liable to have issues like gotofail), and you can use templates to build safer ADTs. These are strong benefits in that it's a lot harder to make mistakes as a developer, but there is a strong tendency in this corner of systems developer to assume that stupid mistakes are a fault of the programmer and not the language, and so such benefits are considered flaws because it means letting in stupid people.
I have to disagree in this case. I think the rationale here is that a working, productive mastery of C suggests a developer of a certain caliber. For many projects you would be right, it would be good to encourage the more junior developers to join the project. But, for the Linux kernel, for the core of one of the most widely-deployed pieces of software on the planet, the foundation of countless systems, many of which are performing critical functions, I, frankly, think it's good to filter the dev team for properly competent devs at every possible juncture. If rejecting C++ keeps the noobs out, that's a good thing.
Possibly, but that's still pretty silly. Like...I am a cautious programmer by nature. I can write C. I understand the language and its semantics at a fairly intuitive level. I am still cognizant that a moment's inattention means that I am going to screw up in ways that I literally can't with a language that has a scope guard (to say nothing of typing that isn't based on how wide the data structure is, that sort of thing). Not using a language more featureful than C--even to the point of literally banning every feature from the language that isn't a nonvirtual dtor--doesn't "keep the noobs out". It does, however, create classes of bugs. If anything, a "noob" is less likely to realize the danger they're in when fearlessly[0] writing code!
Recognition of my own limits is most of why I don't write C, and if I absolutely must interop with C (passing through to Ruby or whatever) I write the thinnest, dumbest layer I can between it and C++. (These days, I'm trying to go towards Rust for these tasks, but I know C++ much better.) C just does not make you the hard man that many C devotees think it does, that's all.
[0] - This is mostly a compliment and only a little tongue-in-cheek. Novices being willing to write code that I have to think about analytically to feel safe when writing it can, in the general case, often work well enough/long enough to get by.
The problem is that in early 1990s, when Linux started, no viable alternatives existed. Pascal required a standard library; Modula-2 did not, but it was late to the scene. C++ was poorly supported, and even more full of hidden traps than C. Ada was theoretically a good choice, but accessible compilers did not exist.
C had widespread use, 20 years of history, many compilers, including a free (GPL'd) GCC, wide platform support. Because the language is so compact and simple, these compilers were mostly reliable, there are no complex features that are tricky to implement.
Hence the choice.
Now we have a much wider choice, we have Rust, we have ATS-lang, we have good-quality C++ compilers, we have various tools to synthesize verified C code from higher-level code, etc. We can hope than in 10-15 years we could see e.g. a viable OS kernel written in Rust.
I don't disagree with you, but I think I can steelman Torvalds' position a little bit:
Low-level development is touchy. If you're not extremely careful, you're going to make errors which no language could possibly prevent, which could very well hard-brick some poor schlub's gear. Selecting for people who know the most "be careful" of all the "be careful" languages means selecting for people who are at least somewhat less likely to make errors like those.
Quite frankly, even if the choice of C were to do *nothing* but keep the C++
programmers out, that in itself would be a huge reason to use C.
lol, thanks for thatIt's not that you can't do realtime in C++: it's that you have to fight against lots of C++ developers who want to apply the non-realtime C++ popular idioms.
For example: using interface classes for mocking objects with googletest, the result: virtual methods everywhere..
[0]https://wiki.osdev.org/User:Sortie/Sortix_Thread_Local_Stora...
[1]https://gitlab.com/sortix/sortix/tree/master/kernel
[2]https://sortix.org/libz/
[3] https://sortix.org/os-test/