Monday, June 7, 2010

Learning C++

C++
Recently I joined a new project at work. It's some application running on an embedded Linux platform. So it was decided that we would write it in C++. C++ is great for these kind of jobs, where you have limited space and processing power.

The only problem was, I had never worked with C++ before. Why was I even assigned to the team you ask. Well, I had previously been working on a related project for the same client. So I had a lot of domain specific knowledge that the other team members didn't have. Also I'm the resident UNIX guy so I would help them when their machines started acting up.

So there I was learning C++ as I went. Reading a lot of books by Scott Meyers and a ton of BOOST documentations. And after a couple of months I'm still a C++ rookie. Frankly, I didn't think it was a Language worth learning. I though it was outmoded and inferior to modern languages.

BOOST
The BOOST library is an amazing piece of software. I can't imagine where we would be without it. From Wikipedia:


"The BOOST libraries are aimed at a wide range of C++ users and application domains. They range from general-purpose libraries like the smart_ptrlibrary, to OS abstractions like Boost FileSystem, to libraries primarily aimed at other library developers and advanced C++ users, like the template metaprogramming (MPL) and DSL creation (Proto).
In order to ensure efficiency and flexibility, Boost makes extensive use of templates. Boost has been a source of extensive work and research into generic programming and metaprogramming in C++."
Most of all I was pleasantly surprised to see how many functional programming features is provides. I mean I use boost::bind, boost::function or boost::signals every single day. boost::bind allows you to create a callable object and bind to an arbitrary member function. It also allows partial function application and the like. There is also the BOOST lambda which allows you to use lambda expression just the way you're used from FP languages.


Valgrind
I've also installed Valgrind on our development machines. We generally use it to detect memory leaks and other memory management issues. Apart from suchmemory checks, it also features several profilers. But the coolest feature IMO is Helgrind, which can detect race conditions in multi-threaded applications and/or improper locking of resources.