I created C++ because I needed something really good at a low level but still allowed a good level of abstraction. I was inspired by how C did low-level and how Simula did object-oriented programming and abstractions. I got to learn each language from the masters. At Bell Labs, I had Dennis Richie and Brian W. Kernighan just down the corridor, and while I was doing my masters at Aarhus University, Kristen Nygaard was a visiting professor. I took the object-oriented concepts (classes and class hierarchies) from Simula and put them into C thereby speeding them up so that you could actually afford to use the abstraction mechanisms. A lot of the languages at the time and even today that allow high degrees of abstraction don't also allow you to run efficiently on various forms of hardware. This is what makes C++ so useful for complex programming
Why C++ works well for complex systems.
There is a reason why they use C++ in space where you can’t send a repairman. If the web app doesn't work too well - tough. But if the brakes under your car don't work well - that must not happen.
I think people make a mistake when they think programming and coding is one thing. Making a web app is very different from building the infrastructure for something. There's a more arty aspect to the web, whereas the infrastructure stuff is engineering. I think people doing these two things should by and large be educated differently and they should be using different tools. If the web app doesn't work too well - tough. But if the brakes under your car don't work well - that must not happen. We have to make sure - and we do. I mean C++ is running on L2 and on Mars where you can't send a repairman - that's the kind of thing I think about. - Bjarne Stroustrup, Creator of C++ , speaking on the alphalist CTO podcast #61
Why is C++ one of the most energy-efficient languages?
I'm not saying that every program in C++ is efficient. That would be absurd because not everybody needs to optimise to that extent. It would be a waste of time to spend a lot of time really doing the optimal tuning of a piece of code which doesn’t need it. [for example] If you have plenty of resources and plenty of time to calculate the answer, you just write less tuned code. But if you need to tune things - you can. - Bjarne Stroustrup, Creator of C++ , speaking on the alphalist CTO podcast #61
C++ excels in its ability to optimise for energy efficiency. For example, if you are running a large server farm - let's say tens of thousands of processors - then your electricity cost is going to hurt you if you are using an inefficient language. But there are always trade offs. Do you want to spend your money on building more and better software or do you want to spend it on electricity? It depends what your needs are and what you're willing to pay for. Maybe you don't have programmers that can write efficient code, or maybe you have free electricity or maybe you do not need microsecond response times or Maybe the battery on your cell phone is big enough. But I'm interested [in optimising C++] where the answer to both questions is no - we need to do better.
When is C++ more efficient than C?
C++ is very good at computing things at compile time. Anything that has to do unnecessary computations at run time is going to be slower. There are examples of C++ beating FORTRAN in dense matrix dense linear algebra which is its domain and also cases where C++ does better than C for system programming. The GCC C compiler is actually written in C++.
Is C++ losing popularity?
Not really. You hear a lot about new languages, but it actually appears that the C++ user community grows faster than several new languages put together. It's easy to grow by a high percentage if you have hardly any users. But growing from 5 million to 7 million is not a dramatically large percentage increase. Also, people talk about new languages much more than they talk about older languages So it appears to me like noise - we always overestimate the use of newer things.
Does C++ ever borrow ideas from other languages?
I think borrowing directly doesn't seem to work. Because any individual feature fits into a type system, fits into other features that work together. You want sort of a dense network of facilities that works in combination so you can't just take something.
Once through, we did think of using Java as inspiration when we needed a formal memory model for C++ to standardise the concurrent mechanisms that we have been using for decades. I thought ``Java has got a good one - Let's take it.”. That would be an example of learning and taking facilities from another language.But it turned out that experts from Intel and IBM came and said, “No, you can't do that. Because if you take the Java model, you will slow down our JVMs by a factor of 2.5 (or something like that).”
In other words, if C++ had the same relatively simple model as Java, all Java code would slow down significantly. And you just don't do such things. So it took 2-3 years to build a memory model for C++ that allowed the very highly-tuned and very highly-optimised [C++] code [implementing JVMs] to actually work as fast as the hardware allowed. This, of course, is seriously criticised for being too complex as it's not as clean and simple as the Java one. But it is exactly what allows the Java one to be clean. Also, of course it took a long time. People criticise the committee for being too slow, but we had to solve the problem - the real problem.
Why do people criticise C++ so much?
We know the problems of C++ - so everybody can criticise that and complain. But we don't know the problems of RUST and Go if/when they reach a new domain.
[The root cause of] a lot of the complexities and so a lot of the problems in C++ is in the breadth of its use. - Bjarne Stroustrup, Creator of C++ , speaking on the alphalist CTO podcast #61
It gets into things where other languages haven't gone yet and when they get there, they will get some of the problems we had. For example, we worked very hard to get a memory model for C++. RUST doesn't have a memory model yet - it will probably have to get one one of these days.
Where does C++ need improvement?
C++ isn’t perfect. It would be great if it had a standardised package manager and there are a few other features we are working on for C++ 23. But it’s an evolving language that is always adapting to users’ needs and we have an annual conference just about the language.