Stroustrup on C++

Last week, the IEEE Computer Society Austin Chapter hosted a presentation by Bjarne Stroustrup, the inventor of the C++ programming language.

The event was amazingly well attended. I'd guess 250 people or more. Stroustrup was an entertaining presenter, talking more like the Bell Labs hacker he was than the Aggie academic he is now.

The presentation was, essentially, a sales pitch for the C++ programming language. Some points were convincing, some less so. One point he made effectively is that C++ is a good choice for systems programming. He highlighted how, for instance, it offers reliability and repeatability not available in a java implementation. The biggest knocks C++ takes, primarily by people advocating lower-level languages such as C or assembler, are size and performance. He claimed C++ programs can be reasonable size, without resorting to tricks like partial implementations that dumb down the language. He also claimed that C++ performance can be excellent. He presented a numerics benchmark. The C++ implementation performed so well, you could see the two inflection points as the test filled the L1 and L2 caches of the processor.

The second point was that C++ templates and containers are good. Of this I'm less convinced. I agree they are extremely powerful, in that they offer a way to generalize the datatypes used in classes. Nonetheless, templates make my head hurt. I understand their appeal and I'm sure, with time, I'd become more comfortable with them. My fear is how well understood this all is. Are such programs easily understood and maintained? Would I just end up writing elegant code that nobody but a few experts could figure out? I'm not sure.

At this point, I'm arguing mostly out of ignorance. Sometimes you see a language feature, such as exceptions, and it's readily apparent how cool it is. Not so with templates. Maybe with time I'll warm up to them. All I need is a test case to try them out. Unfortunately, I've been so badly corrupted by perl, I hardly use anything else these days for small systems programming problems.

Comments

Comments have been closed for this entry.

re: Stroustrup on C++

Sorry to have missed the presentation. I still have his book, though.

As a former longtime assembly language programmer (yeah, we had to use the letter 'l'), I agree. I stopped using assembly in the '90s mostly because of gcc. Looking at the i960 code output by gcc, I realized it could optimize as well as or better than I.
Containers? templates? what are those? Where's the algorithm?

But a C++ compiler will still compile most of your old K&R C with a few minor fixes :)

re: Stroustrup on C++

The algorithm is in <algo.h>, of course. ;)

I'm using templates in a couple of places in my code at work. Our main use for it is to be able to write the linked list, or red-black tree code once, and then have it work on several different datatypes. We don't get into the really funky stuff you can do, but the simple stuff has saved me a lot of time. (I've heard of, but not seen, a Turing Machine written in templates, as in the template instantiation was the running of the Turing Machine, and the resulting program was the output. (Google shows something similar here But I think everyone agrees that that was an abomination, and should be destroyed.)

re: Stroustrup on C++

C++ is my favorite language, and I have to say that templates are an amazingly powerful way to program. Don't be fearful of them at all. The most difficult part of templates is the fact that the messages generated by the compiler can be a bit cryptic. Take your time and learn to read the error messages.

The Standard Template Library is an immensely powerful tool, and once you learn it, you'll start thinking about programming in a completely different way. Let me give you an example: learning the Standard Template Library has made me wish for another feature in the C++ language. That is, a Lambda keyword, similar to lambda in Scheme.

I work with a lot of people who always choose C over C++, because it's "simpler". The problem is that their C code ends up filled with pointers and insane reimplementations of data structures. If they had written their code in C++ it could have been 1/3 the size, used the STL data structures, and not contained a single pointer in all of that. And run just as fast.