C++ : The most misunderstood language • Cargo-culted snark: • templates are weird! • omg boost takes so long to compile • i’ll have to manually manage every memory allocation • gahhh derp derp herrrrrrrrp // hacker news
The Best C++ Feature • RAII: “Resource acquisition is initialization” • Crappy acronym, simple concept • Acquire resources in constructors, release them in destructors • Deterministic destruction does the rest • Java try-with-resources is an ugly hack
RAII struct my_object! {! void do_something()! {! lock_guard g(mtx_);! do_something_with_state_that_might_throw(state_);! // mtx_ is released regardless of how function exits! }! mutex mtx_;! state state_;! };!
Lambdas! void lambda_lambda_lambda();! {! auto my_simple_lambda = [](){ cout << "hello, world\n"; };! // prints "hello, world” ! my_simple_lambda();! int i = 0;! // captures i by copy! // prints 2, but i is unchanged in outer scope;! auto my_copy_capture_lambda = [i]() { i+=1; cout << i; };! my_copy_capture_lambda();! ! // captures i by copy! // prints i+y, i in outer scope is incremented by y! auto my_ref_capture_lambda = [&i](int y) { i+=y; cout << i; };! my_ref_capture_lambda();! ! // [&] = capture all by reference;! // [=] = capture all by copy! }!
Better Toolchain • clang vastly superior to gcc • comes with static analysis, AST introspection • even writing analysis plugins is reasonably simple • lldb > gdb too, once you relearn all the commands
Conclusions • The combination of C++11 and the Clang toolchain makes C++ worth checking out again • Or maybe I just have Stockholm Syndrome? • … your thoughts or questions?