r/cpp • • Jul 13 '22

Why does Linus hate C++ ?

308 Upvotes

436 comments sorted by

View all comments

Show parent comments

69

u/SergiusTheBest Jul 13 '22

C makes a lot of sense for kernel development.

I can see only one point that makes sense: lack of C++ compilers or their bad shape 30 years ago.

104

u/snejk47 Jul 13 '22

People. His main issue is people. It's a lot easier to review code in C and harder for people to write hard-to-read, more bogus code in C than in C++. There are thousands if not hundreds contributors. If I recall correctly he tried long time ago and amount of babysitting and unknowns was to high for stability he targeted. Rust has more high level features but also compiler is very unforgiving taking much of such work to assure things are correct. He also has written app in C++ and QT for scuba diving if I recall correctly but this was his personal project.

35

u/SergiusTheBest Jul 13 '22

It's easier to review less code and C++ allows you to write less code. For example, by using C++ RAII and simplifying resource cleanup significantly comparing to C.

74

u/condor2000 Jul 13 '22

It's easier to review less code and C++ allows you to write less code

It can take longer to review properly if uses complex template designs or even just a lot if virtual functions

28

u/[deleted] Jul 13 '22

The C equivalent to complex templates are complex macros. Is that better to review?

2

u/disperso Jul 14 '22

IMHO, yes. I'm not saying that it produces better code, but given that macros are much more limited, I'd say that you just can do less, have to think less, and end up having limited C code and dealing with it.

But that is probably subjective, with different people having different skill-set and preferences.

→ More replies (1)

39

u/Jannik2099 Jul 13 '22 edited Jul 13 '22

even just a lot if virtual functions

Ever seen dynamic dispatch in C? Know how error prone it is? Know of ubiquitous it is in the kernel?

11

u/afiefh Jul 13 '22

Ever seen dynamic dispatch in C?

I still have PTSD from that one code base I worked on 5 years ago...

63

u/TheThiefMaster C++latest fanatic (and game dev) Jul 13 '22

The equivalent C code to accomplish the same goal is often far worse.

These arguments always compare the most complex parts of C++ against normal C code, not equivalent C code.

→ More replies (11)

15

u/serviscope_minor Jul 13 '22

It can take longer to review properly if uses complex template designs

If the complex template designs aren't materially benefitting the code, then reject the pull request. Just like if someone goes bananas with C macros.

even just a lot if virtual functions

Linux has a ton of virtual functions. They're all done by hand which is always more complex than having the compiler do it for you.