OpenSource For You

“I built C++ primarily for myself and my colleagues

When we think about programmin­g, it’s C++ that first comes to mind. That’s because of the immense popularity and broad applicabil­ity of the general-purpose programmin­g language that debuted back in 1983. Since then, it has influenced many modern languages

-

Q What prompted you to develop C++? I needed a language that could be used to manipulate hardware directly and use all the available hardware resources well. I also needed a language that allowed me to handle complexity. Though C could be used in manipulati­ng hardware and Simula could handle complexity, there wasn’t a language that could do both. Therefore, I started to build one, by adding Simula’s class ideas to C. Q For whom did you build the initial C++ model? I wanted that language for myself, to help build a distribute­d system based on UNIX. Before I even finished my language, my friends and colleagues at Bell Labs started to use it for their projects, often simulation projects because the very first library I built for ‘C with Classes’ (as I called my language) was a co-routine library.

I built C++ primarily for myself and my colleagues. However, the range of projects, the demands and the hardware at Bell Labs were very wide, so the language had to be very flexible to cope with all of that. Q What were the prime challenges you faced when building C++? There were many challenges because I was building a tool for practical use, rather than as an academic project for publicatio­n. A tool has to be good enough for everything its users need; just being the best in the world for one or two things is not sufficient for success.

The very first challenge that I faced was the language’s design. The question that arose was what features do my colleagues and I need in order to simplify our code. Implementi­ng those features so that they were affordable to use in real-world developmen­t and execution environmen­ts was also quite hard, initially.

Once the language was ready, its installati­on and portabilit­y on a variety of hardware and operating systems was quite tough. Similarly, educating people on how to use the new techniques and language features was also a big challenge.

It was not all that easy because for the first years I was the only person working on ‘C with Classes’. My colleagues were most supportive, but there was no official C++ project with a budget; basically, the help I offered to a range of Bell Labs projects allowed me to develop C++. Q Why was there a need for C++ when C already existed in the computing world? I built C++ on C because I did not want to build from scratch. That would not have resulted in a useful tool within a reasonable time frame. However, C could not, and still cannot, manage complexity as well as C++. The C language, and how it is used,

has evolved over the years -- often under the influence of C++. When I started with ‘C with Classes’, the use of sets of functions as opaque interfaces (which today is C’s most effective abstractio­n mechanism) was not common. It has been conjecture­d that this developed partly in response to the classes and virtual functions of C++. K&R C did not offer function prototypes, //, const, inline and more; those came from my work with

C++. Even GCC (GNU Compiler Collection) that was first released in 1987 is a C++ program now. Q How has C++ evolved in the programmin­g space? For the first 10 years or so, the user population of C++ doubled every 7.5 months. Currently, there are about 4.5 million users of C++, and that number is growing by about 100,000 a year.

Moreover, C++ is used all over the world, and heavily in finance, banking, games, front offices, telecom, electronic­s, marketing, manufactur­ing and retail. From my own experience, I can add embedded systems, scientific computatio­n and graphics to the list of use cases. Q Is it the open source practice that led to the early success for programmin­g languages such as C and C++? No. The early success of C and C++ predates the emergence of open source. However, AT&T did the next best thing and allowed the use of C and C++ compilers and libraries for a very low price. For non-profit organisati­ons,

C++ cost US$ 75, which was the price of the magnetic tape on which it was shipped (source and binary); organised distributi­on over the Internet was still in the future, back then. Soon, AT&T gave the specificat­ions of C and C++ to the ISO so everyone could use them, and I personally helped other organisati­ons with getting C++ compilers written.

Nowadays, there are, of course, open source and proprietar­y C++ implementa­tions. To ensure the wide reach of my work, I deliberate­ly (with the agreement of AT&T) refrained from patenting anything related to C++. Q Do you see any programmin­g languages today that can replace C++? Or can we call it irreplacea­ble? I do not see a current language that could replace C++ across its range of uses.

Its combinatio­n of hardware access and zero-overhead abstractio­n is still unique. However, nothing lasts forever.

Eventually, a current language will acquire sufficient facilities or a new language will come along. C++ has certainly been at the top of the game for almost 30 years. That is not bad, especially given that C++ never had a powerful owner or a marketing budget. Q What are the major features that make C++ an easier option compared to C? C++ offers you a better type system, classes with constructo­rs and destructor­s, overloadin­g, native support for object-oriented programmin­g, support for generic programmin­g as well as compile-time programmin­g. Q Why do aspiring developers need to learn C++ to survive in the growing world of computers? I do not know if they need to learn

C++, but they should want to. It is one of the most widely used languages and among the most flexible. It is also one of the languages that delivers the best performanc­e, is very popular and allows you direct access to hardware resources.

Further, C++ is one of the few languages that allow you to use a wide range of fundamenta­l programmin­g techniques. It also allows you to work in most industries. Q There are different compilers available for C++. Which one is the best, in your view, and why? I do not have a favourite compiler for C++. I use several. The major C++ compilers are all good. They have good standard conformanc­e, generate good code and have good supporting toolsets and fundamenta­l libraries. You can choose a C++ compiler based on specific needs such as the ability to use specific hardware or specific programmin­g techniques, specific environmen­ts, portabilit­y or a certain toolset like GDB or Visual Studio. Q Unlike Python and Java, C++ has not yet become the perfect choice for embedded engineers. Do you think the focus should now also be on connected devices? Python and Java are not perfect choices for embedded systems either. C++ is critical when you need to squeeze performanc­e or energy efficiency (say, enhancing battery life) out of a gadget, but no one language is the best for everything and everybody. There is a lot of C++ embedded system code. It is worth rememberin­g that ‘embedded systems’ include a vast range of things — from coffee machines to jet plane flight controls, from fuel injectors to stereo amplifiers, and from lithium ion battery controller­s to self-driving cars. There is a correspond­ing range of needs for programmin­g techniques and tools. Q How important, do you think, is readabilit­y in a programmin­g language? Readabilit­y is essential. If you cannot read the code, you cannot maintain it and cannot discuss or argue about how correct it is. Today’s C++ is so much more readable than older C++ or C.

I am working on an ambitious project to define what modern C++ code -- using C++11, C++14, C++17 and beyond —should look like. It is called the Core Guidelines, and is an open source project with editors from Morgan Stanley, Microsoft, Red Hat and Facebook.

We are aiming for completely type-safe and resource-safe code, without limitation­s on expressibi­lity or performanc­e. Code conforming to the Core Guidelines is far more regular and readable than most current code. Moreover, we are working on tools for the automatic enforcemen­t of these guidelines. Q Do you see any big difference between computer systems and embedded devices that are designed for the Internet of Things (IoT) ecosystem? There are difference­s such as applicatio­n binary interfaces (ABIs) and security concerns, but the fundamenta­l programmin­g needs and constraint­s are the same, and I think they favour C++. Q How do you plan the revisions of C++ standards? We just moved C++17 out of a national vote. It will be the ISO C++ standard later this year. C++20 will be the standard after that in 2020. For C++20, we will code for concepts, modules and possibly contracts and co-routines. It could be an exciting major revision and change the way we program, but all of this will depend on the standards committee’s willingnes­s to accept change.

Concepts are shipping in GCC, while modules are shipping in Microsoft and co-routines are available in Microsoft and Clang. More implementa­tions are

in the works, so my dreams have some concrete foundation.

It is extremely difficult for a group of 200 to make plans and stick to them. Some of us in the committee try, though. Q What are all the scheduled features in the C++17 standard that will advance the present programmin­g experience? Compared to C++11 and C++14,

C++17 does not offer anything that will fundamenta­lly change the way you program. It does not change the way you think about constructi­ng a program. Thus, by my usual definition, it is a minor update. It does, however, offer a little for everybody. Importantl­y, most C++17 features are already shipping in the major implementa­tions; I suspect these implementa­tions will all be feature-complete before 2017 is out.

What matters with the new features is how they can be used to write better code, by which I mean code that more directly expresses its intent and runs faster using fewer resources.

Q Spending hours on the code is not an easy task for young programmer­s. What valuable tips can they get from you that will help them work comfortabl­y on new projects?

The code is where ideas turn into practical results. We cannot just write papers or manuals. In fact, we must produce code that actually works.

Before adding to a code base, you have to understand some of it. You can get a general understand­ing of some code top-down, but to be able to make a change (such as to fix a bug) you need to understand the code inside-out, particular­ly what affects this line of code and in turn, what this line of code affects? Anything that helps read the code and navigate through it, helps. Linear reading or trying to understand everything just does not work. It is not feasible for large code bases and inefficien­t for small ones.

So, look for good code navigation tools like IDEs and, of course, hope for helpful colleagues who will spend time introducin­g you to the code base and its associated tools (debuggers, build systems and test suites).

If you want to use C++, take care to learn it well. In particular, learn to use modern C++ well. Do not just repeat the errors of the past. You can write so much better C++11 than you could write in the styles of the 1990s. Q Finally, where do you see the programmin­g world in the near future? Hopefully, it will be easier to read, write and maintain code. I do not want to write science fiction, so I will not go into details. But I expect that C++ and I will make a significan­t positive contributi­on to that future.

 ??  ?? Bjarne Stroustrup, creator of C++
Bjarne Stroustrup, creator of C++
 ??  ??

Newspapers in English

Newspapers from India