3 ms·
If I understand correctly, Linus was not only dismissing C++, but also the object-oriented programming paradigm. His main concern was creating abstractions that
by copperx 11y ago
If I understand correctly, Linus was not only dismissing C++, but also the object-oriented programming paradigm. His main concern was creating abstractions that result in inefficiencies which most of us consider not bad enough for writing userland software.
What's interesting is Stroustrup proudly states that C++ provides "cost-free abstractions". I'm not too familiar with C++ implementations; is it fair to say that?
- ktRolster 11y agoWhat's interesting is Stroustrup proudly states that C++ provides "cost-free abstractions". I'm not too familiar with C++ implementations; is it fair to say that? C++ was invented when efficiency was measured in instruction counts and processor cycles, so he optimized his language in those terms. Processors are much more complicated now, and cache alignment and branch prediction and pipelining are much more important for efficiency than counting the number of instructions something takes.
- Scea91 11y agoBut even then C++ is basically cost free if used correctly. Of course I am not comparing it with some hypothetical hand optimized assembly, but specifically when considering cache alignment C++ has massive advantage in this area compared to languages like Java. Compared to C there is nothing in C++ that would make cache alignment more difficult by design.
- Ace17 11y agoIt's fair, in a sense that it's possible to implement cost-free abstractions in C++. However, you have to know what you're doing: some of the C++ abstraction mechanisms will cause the compiler to insert executable code at places a C programmer might find unexpected (e.g constructor and destructor calls). In one word, you still have to learn how to use the language properly, and it's difficult - but definitely worth it. Interestingly enough, some of the abstraction mechanisms provided by C++ (templates, inheritancy, polymorphism, ...) can also be partially simulated in C, with a lot of effort (the Linux kernel makes a heavy use of them (macro-powered)). It's just that C++ makes those things easy to do ... allowing your incompetent teammates to easily shoot you in the foot.
- acqq 11y ago> is it fair to say that? If the programmers wouldn't be dogmatic it would be possible, but most are. It's "we use boost/smart pointers/whatever for everything" programmers that produce the mess that I also wouldn't like to have in the kernel.
- rkangel 11y agoOften, but not always. One example is calling virtual functions. There's an extra memory lookup to resolve the function call at runtime. Almost all the time, that extra single memory lookup is irrelevant. But just occasionally, that cost can have an impact. In principle it's no different to C - you need to understand the basics of what code the compiler is going to generate to do what you're asking it to. In C++ the constructs are much more complicated and that mapping becomes less clear.