Beszélgetés a C++ múltjáról, jelenéről és jövőjéről Bjarne Stroustruppal

Május 9-én lehetőségünk nyílt részt venni a Craft konferencián, ahol a Morgan Stanley-nek köszönhetően készíthettünk egy interjút a C++ megalkotójával, Bjarne Stroustruppal. A konferenciát a budapesti Vasútmúzeumban tartották meg. Az interjú keretében 30 percet beszélgettünk a C++ múltjáról és jövőjéről egy régi vonat vagonban, ami egy igazán kellemes légkört biztosított.

(Figyelem! Az interjú innentől angolul olvasható tovább.)

Yesterday you gave a lecture at our university, Budapest University of Technology and Economics, how did you like it?

It was nice to visit, I saw some of the projects and they were very interesting. I like the engineering angle to things like programming gadgets, sensors and such. I think there was the other university where they were doing static analysis, which is really good for supporting reliable software, so it fits together.

How does it feel like to be called a living legend, the father of the C++ language?

It’s slightly embarrassing of course but on the other hand it’s a recognition that what I and the C++ community has been doing is very useful and that people like it. It’s very complimentary and nice, and it’s really good to have done something that makes a difference. It feels good.

Was there a main goal when you created the language? Was there anything missing from the available languages at the time?

Oh yes there was, that was the reason I did it. I didn’t actually set out to build a programming language, I aimed to build a system, and there was no language that could build that system. I wanted to build a distributed system and I needed something that could deal with low level stuff like device drivers, memory managers, process schedulers, and I also needed something that could do high level stuff like components of the distributed system, and there was no language that could do both, that’s why I ended up writing one.

Do you think it has achieved that goal?

Yes, other people ended up building such systems, I never got around to do it though, because I got distracted into building the language and helping C++ users. But yes, C++ has been used to build really interesting distributed systems. The banks for example have a fair number of distributed systems, you can even understand banks as very large distributed systems moving data around. The Deep Space Network, that was used to talk to the rovers on the Mars, is an example of the kind of systems I couldn’t have imagined at the time, but it’s the kind of distributed system I was interested in and it is written in C++. Some of it is on the Mars and some on the way to it.

You started making C++ for your distributed system project, but now it’s really widespread. Do you still consider it to be your child or project or has it become more of a community property now?

I mean I feel responsible for it. When you put something out in the world you are responsible for it. That doesn’t mean I own it, doesn’t mean I’m the only one working on it, but I try to keep it true to its aims and I try to keep it clear and improve it for what I think it should be improved for. That’s not always easy and not everybody agrees on what it should be, so I try arguing for certain things and sometimes I succeed, C++20 for example looks really good.

It seems like there is a spirit to the language, a main vision behind it: the expressivity and that you can build anything from basic building blocks.

Yes, definitely. There were languages at the time that were carefully designed so that you can only do things that its designer considered to be good, so these languages always fit this mould. The languages being designed today have the same kind of idea, that the designer or designers know what’s good and they want to be sure that the programmers only do what’s good. I never was too certain about what was good, I was actually quite convinced that I couldn’t possibly know what was good in all the fields in which C++ could be used. I actually had a rule that said it’s more important to enable people doing something good than to prevent people from doing something bad. And when you think about that reminder it is really hard to define good and bad, you know why you can’t design a language that way.

People always ask why this or that is not in the language, for example register handling. You usually answer that C++ has a place in between high and low level languages and it should stay in that place.

You don’t want it to be just a low level language and you don’t want it to be just a high level language. The key idea is that you can deal with hardware really well and then you can abstract at zero or very low cost. Actually right high level code runs essentially just as fast as the low level stuff. Efficiency and low level is not the same thing.

Will expressibility always be the first thing to consider when introducing new things to the language?

I always consider flexibility, expressibility, generality, performance, zero overhead and such. I take this quite seriously as I said today at the talk: not a byte, not a cycle. I don’t want to compromise in these things, but you also have to pay for what you get, these things are not cost-free, but there shouldn’t be any unnecessary cost, any sort of fat on the system. I always consider that and it’s arguable if the language still meets this criteria.

Did you ever think that C++ would be this popular?

No, I had no idea. I mean when I started I was just doing it for myself, and then my colleagues started picking it up and using it, then one day I found I was a language designer. I hadn’t set out to be that, it’s just apparently my ideas were good, and even more: my problems were good so I could spend a long long time solving these problems and making things better and better for a larger and larger group of people. It’s not that I set out to build the world’s greatest language or something like that, that thought never even entered my head.

I heard you mention that if there was a language that came out strictly better than C++ in a fair competition, you would be happy that the world had progressed.

You have to hope for that!

What do you think made C++ popular while so many other languages have declined?

Well, I mean they build 200 new languages every year and 200 of them die every year. Partly it was sort of luck, I found a problem that was really important at the time and I came up with some reasonably good solutions for it that worked at the time. It wasn’t that I came up with some solutions that might be successful ten years, hence when computers will be more powerful it’s a fundamental rule of evolution to be viable at all times. You can’t just wait while being useless for couple of years and then come back, you have to keep up, you have to keep being viable on the hardware and for the programmers that exist at the given time. In this we seem to have succeeded in. The primary problems were so fundamental we had to work on them: this level of software between the hardware and the higher levels of software is a very important niche, every system has some of it. And with the rise of IoT, more computerized gadgets and such, there is more and more need for something in that space. Also, I like the fact that it isn’t a proprietary language so you don’t have the proprietary language from microsoft fighting with the proprietary language from Apple fighting with the proprietary language from whatever. That’s where the ISO standardization comes in. Nobody owns it, so everybody can use it without fear of being clobbered by some unfair competition.

Do you have any recommended compilers?

Actually the major compilers are good: GNU, Clang, Microsoft, these are all good. The front ends for embedded system are usually good too. The embedded system backends are usually not quite up to snuff yet, and I hope they will improve, but actually from a compliance and tool point of view the current compilers are pretty good. Also I don’t have a favorite, on the contrary I always try to use two so i don’t get hooked on one of them only. I’m keen on portability.

Are there any plans to make the language more supportive for embedded systems?

I think that if the embedded system industry got more up to date with C++ then they would find that, that is the easiest way of improving it. It’s not new features they need, it’s better backends. After that we can start looking at how to better support them. The work on concurrency, on models of concurrency is important and will be extra important in the embedded systems industry. I think there are good steps in that direction.

Do you think that if efficiency became irrelevant due to things like quantum computing or powerful hardware so much that micromanaging resources is not an issue anymore, C++ will be left behind quick-development focused languages like Java or C#?

No. Certainly so called managed languages, garbage collecting languages have an object model that just makes them slower than C++. You mentioned quantum computers, I think they will be gadgets that will sit on the side and that you will ask questions from and it will answer back. It’s not normal programming, if you look at the way you specify those, it’s basically by equations. The other thing I was going to say is that people have predicted that computers are getting faster and therefore we don’t need C++, they have been predicting that for at least 30 years and they haven’t been right yet! Furthermore, computers actually stopped getting faster, single processors stopped getting faster in 2005 or so about. One of the reasons C++ is getting increasingly popular these years is exactly that computers are getting slightly less fast. Furthermore, people want performance per what? They look at the energy efficiency and such, and there C++ has a fundamental advantage, that it goes directly to the hardware, it doesn’t go through an interpretive step and it doesn’t use as many indirections as other languages. That’s where the advantage is, back to the fundamentals again: it’s good at hardware.

Are there any plans for something similar to C++ for quantum computers, like a Q++?

Almost certainly somebody will call something Q++, but really I think that’s a totally different model of computation so the question is not well phrased, we wouldn’t know what it will mean.

Is there a route for C++ to follow or the next step is always the biggest problem that presents itself?

There actually is a plan. C++20 looks remarkably like what I outlined in 2015 and this is one of the things I’m emphasizing these years, due to people thinking that because we have these three year releases we’re just picking up whatever seems good. No, there actually is a plan. We always knew that we needed Modules we just didn’t know how to do it and we have been working on this for a long time, the problem is described in The Design and Evolution of C++ from 1994 and we knew even before that. Concepts has a history going back to the earliest “C with classes”. I wanted to be able to say things but I didn’t know how to say them and how to make them efficient enough, but now I do. It took 40 years, which is a long time. There actually is a set of ideas that goes back a long time. There is the question about static reflection that’s still in the future. Some of the ideas even stretch back way more than a decade, it’s not like we just go out and add things because they are fashionable. We look rather carefully at what the real problems are, and then try to solve them, and quite often it takes decades, not months.

So the plan for C++, does it go for more simplification and elegance or can we expect new out-of-the-box solutions like the standard containers?

Well, I mean we have the standard containers and we can get more standard containers. It’s more like you can’t simplify the language because then you break peoples’ code. When we talk about simplification, there are a couple of things we mean: new features that allow you to solve old problems better, like concepts or modules for that sake, and then there are facilities that allow you to express ideas better. The classical example is the range-based for loop, it allows you to express the most common loops more concisely, and sometimes it is easier to be optimized. So we try to have sort of levels for usage, simple rules for simple cases and then the more complicated stuff for more unusual examples. That’s what I refer to as the “Onion Principle”, because when peeling layers off the onion you cry more each time you get a layer off, because now you get into a domain that’s harder to deal with and easier to make mistakes with. You don’t want to make things impossible, there are languages that simplify things by making complicated stuff impossible, but we don’t do that.

Do you have a metaphor for C++?

I have not found a good buzzword for C++. People make buzzwords that are simpler than I’m willing to say and then they sort of steal the message. People say C++ is object oriented and therefore you should have everything in a class hierarchy and everything should be a member function. I never said that and I never meant that! But it’s such a good buzzword so it steals the message. I wish I could say things more concisely, but I can’t.

I heard you say that you don’t really regret anything in the implementation of C++, but can you think of anything that looking back wasn’t such a good idea but now it can’t be changed because of backwards compatibility?

There are two things: I think the major part of C++ is sound, and I think every detail could probably be improved. The point is that the details are there and so when you add improvements you have to be careful or you will get a bigger language. There are many many people who think you can eliminate a problem by adding something new. The problem is that the old stuff is still there and if you don’t integrate the new stuff carefully you just got an example of what I call the “n+1 problem”. The problem is that you have n ways of doing things, so you add another one now you have n+1, that’s a bigger problem, so you have to be very careful with the integration. Notice that Concepts integrate perfectly with the old stuff, the old typename stuff is just the weakest Concept. If you look at the range-based for loop, it’s really the ordinary C for loop, but using the version with the iterators is a shorthand for writing the standard iterator loop.

Do you think that C++ is a good first language for a programmer?

There is no good first language for programmers because it depends on what you want to be a programmer for. If your purpose is to become a web developer obviously C++ is the wrong answer. If you want to be an engineer for safety critical devices Java is obviously the wrong answer. So let me answer in a way that if you want to be a developer of important systems in the reliability and performance space and if you want be a professional in that space, then C++ is a very good first choice, not the only first choice, but it is a good first choice. And I’m certain of this because I taught beginners for 10 years, and I’ve seen the outcome of it. It can be done, it can be done well and it works. Another reason why C++ is useful is that it allows you to express most of the paradigms needed for serious code development.

What do you think about people almost going into war for their preferred languages?                        

I don’t like language wars, they are too much like religious wars, rationality goes out the window. You can solve most problems in different languages, sometimes in the same way, sometimes completely differently. It comes to the question of what are the important parts of what you are doing and which language fits the best in that. If you have a part that touches the hardware and where you need reliability and performance, C++ is one of the alternatives you should consider. If you do something that doesn’t have safety critical or performance issues then maybe C++ is not your first choice. I think it’s also worth mentioning that C++’s domain has been almost always consistently increasing since day one.

What do you think about the C++ community? They contribute much to the language, like libraries, do you think this is a good model for language development?

The large number of contributors to C++, standard libraries, non-standard libraries, is both a strength and a weakness. Everyone wants a standard GUI, but you can’t get a standard GUI because we have about 25 of them, and we haven’t been able to make any progress in that space, because of the richness of the domain. I mean Qt has more uses than most languages that are supposedly good at graphics. In regards to the standards, there are many things that people want to get in, but it’s hard to pick one version that can do well.

So you have a choice: you can try the benevolent dictator for life model. We don’t have one and we never did have one, and I noticed that this model has problems too. We have close to chaos where we tend to discuss the issues and then eventually get to consensus, there is nothing in C++ that didn’t get a 80-90% approval among all the people taking part.

My programming professor at the BUTE once said that if programmers were rated with stars like chefs and restaurants, the number of stars one would have is equal to the number of dereferences one can handle mentally. Would you say that that is the biggest challenge in C++ getting your head wrapped around memory management or are there more challenging parts of the language?

When I write code, memory management doesn’t tend to be a major problem. Most of the time I treat resource management as a solved problem. We have RAII, constructors, destructors we can build resource handlers, we can move resource controls from scope to scope. This is not where the problems lie anymore. The last time memory management was a problem was in the 80’s.

So now where are the problems?

Now they are in old code and in people writing code that doesn’t follow modern principles. They have to do with things like dangling pointers, we are trying to address that through the Core Guidelines project. There are always performance problems, people always want more. The only thing that grows faster than hardware are human expectations. That’s been a rule of thumb of mine for a long time, since I noticed it. Even at the time when hardware grew amazingly fast, peoples’ wishes and expectations grew even faster. This is worth remembering.

Dealing with old code is one of the major problems. When we try to deal with the complexity of the language through this idea of keeping the simple things simple, then you can have the complicated stuff. But no, the problems are not resource or memory management, we know how to do that.

And finally: When you indent something, do you use spaces or tabs?

I couldn’t care less, but I tend to use tabs because they are faster to type and I’m not a good typer. Of course the IDE-s have their own opinions and I do what the IDE does if I have an IDE.

Based on the answers of Bjarne Stroustrup,

Vélemény, hozzászólás?

Ez a weboldal az Akismet szolgáltatását használja a spam kiszűrésére. Tudjunk meg többet arról, hogyan dolgozzák fel a hozzászólásunk adatait..