Sunday, February 26, 2012

My reactions to Stroustrup's keynote on C++11 style

I finally got around to watching this on channel9. Now, I don't do much C++ myself these days, since most of the code at work is in C#, and the language is rather high in ceremony (e.g. header files) for out of hours playtime, compared with the broad spectrum of widely available and popular languages there to choose from these days; but I do from time to time, so it's always good to see where things are going.

Interestingly, for a C++11 talk, a good 60% of it was about how we could drag the usual run of C-with-a-cpp-file extension code kicking and screaming out of the 1980s and into the early 21st century. In-language lambdas, async/futures and move constructors were touched upon, but where real world examples were talked about, it was showing how actual live code wasn't taking advantage of features that have been available in compilers for the best part of a decade, or longer, to make code simpler, more maintainable, and faster -- often considerably faster. And when I have to do some C++ and have been greeted by files full of almost-C-in-files-with-cpp-extensions, written by people who are writing native most of the time, I know that feel, bro :

>2012
>Not using RAII

ISHYGDDT

The "a lot of people don't know that" moment -- when doing random access insertion or deletion from a sequence, the random access part dominates the insertion/deletion reshuffling to such an extent that whatever the collection size, use a vector rather than a list.

The big takeaway -- despite the folklore, going to low-level 'C' style constructs is premature optimization. The machine code generated by the higher level constructs is often exactly the same as for the hand-crafted lower level code; and at times can be better, as the compiler has more context for optimizations.

Heh, almost makes me want to do something with the language again, if only to keep my hand in.

No comments :