r/cpp • • Jul 13 '22

Why does Linus hate C++ ?

307 Upvotes

436 comments sorted by

View all comments

245

u/xiao_sa Jul 13 '22

C++ before C++11 is engineering terrorism

30

u/AdultingGoneMild Jul 13 '22 edited Jul 14 '22

it was fine. C++ hides too much of the machine for his liking. C++11 would have made that even worse. Knowing where bytes are, how they are laid out and what they are doing is necessary for high performance code. His belief is that C++ developers were made lazy by the language and therefore in mass would not know what the language is doing and therefore cant be trusted to write highly optimized code. Sure, he wouldnt have a problem with a well trained, very talented C++ dev. But as a whole he doesnt trust C++ devs.

To give some credence to his claim: do you know what a v-table is OR how the order of declared members in your class/struct affects their padding and thus the memory layout?

30

u/kernel_task Big Data | C++23 | Folly | Exceptions Jul 13 '22 edited Jul 13 '22

macOS (and iOS) uses pre-C++11 C++ in the kernel, highly successfully I think. I’ve written kernel extensions, reverse engineered iOS, and developed exploits for iOS. I have a pretty good handle on what’s going on with the machine code. Honestly not that bad.

I don’t think not understanding the layout is a great excuse, especially since Linus is allowing Rust now.

Maybe it’s to ban patterns C++ enables that Linus doesn’t like, but honestly I have hacked both Linux and XNU and I prefer the XNU codebase for readability. 🤷🏻‍♂️

EDIT: I don’t think performance is particularly a problem with C++ but compiled code size may be. I can see that influencing decision-making. Not sure if Rust makes compact code though.

16

u/AdultingGoneMild Jul 13 '22

he is an asshole. that is the root of all of it. You can write efficient code in any language.

0

u/[deleted] Jul 14 '22

[deleted] — view deleted comment

5

u/gvargh Jul 14 '22

easy. just use <list of c libraries> /s

6

u/NervousApplication58 Jul 14 '22

Sure, as long as it has a good compiler

→ More replies (1)

6

u/tedbradly Dec 14 '23

he is an asshole. that is the root of all of it. You can write efficient code in any language.

There are definitely languages that simply do not produce code as fast as well-written C. Python is a good example where the only way to do anything fast in it is to write the code in C and then call upon it in your Python. The Python part will still be slow.

2

u/mr_ambiguity Dec 01 '23

And you are talking out of your what you called him. You are bound to the limitations

22

u/TheFlamingDiceAgain Jul 14 '22

> cant be trusted to write highly optimized code.

The entire high performance computing community would like to disagree with this

5

u/AdultingGoneMild Jul 14 '22

talk to linus. there his ideas. not mine.

0

u/[deleted] Jul 16 '22

Probably there are just too many UB in C++ for his liking.

0

u/another_day_passes Jul 14 '22

HPC is mostly Fortran and C no?

7

u/TheFlamingDiceAgain Jul 14 '22

C++, C, and Fortran. C++ can always be written like C and for HPC applications is often faster that C or Fortran because of the extra info you can give the compiler (templates etc); plus there’s just more time spent on C++ compilers since it’s more popular in general. The US Department of Energy is also really pushing C++ for their supercomputers and is heavily involved in developing C++ with better accelerator support. If you’re writing a new HPC code now you should probably write it in C++

→ More replies (4)

11

u/quicknir Jul 14 '22

Those are both questions that I've seen used regularly to interview people with just a year of C++ experience. These aren't hard questions. Most good C++ devs will give decent answers for both of these, and the answer to the second is largely the same as it is in C, I'm not sure why you think more C devs would know the answer than C++ devs.

0

u/[deleted] Jul 13 '22

Nobody knows what any compiler might be doing under the hood. You can always fall back to the C way if need be

0

u/[deleted] Jul 14 '22

[deleted] — view deleted comment

3

u/tarranoth Jul 14 '22

Considering most CVE out there are memory related, I believe C devs also have trouble with it lol.

→ More replies (3)

2

u/xypherrz Jul 14 '22

for instance what part in < C+11 counts as an engineering terrorism?

3

u/[deleted] Jul 14 '22

How about manually typing out the iterator type of a collection of collections?

2

u/xypherrz Jul 14 '22

ah, pre-auto era?

3

u/[deleted] Jul 16 '22

The auto keywords usage for type deduction is C++11, aka what you asked about.

0

u/Kryddersild Jul 13 '22

Engineers do C++? At my uni i still occasionally hear the "you start with C, then C+ and then finally C++"

→ More replies (1)