C++ finally won me over

18 January 2015
In the past C++ has struck me as a language that is nice at a glance but an utter horror at a closer look, and has always left me with the feeling that I should either stick with pure C, or go for a cleaner language like Java or Python. Recently I had reason to use C++ for a specific purpose, and realised it is actually quite a good language that gives more modern ones a run for their money.

Historic use

While I had quite an enthusiasm for C++ in my earlier undergrad days, often using it whenever I had the option to, it dawned on me that my use of C++ was C with classes. Compared to the then-typical C-based ADT usage pattern, I felt my C++ use over C ended up coming down to where the data reference was. In other words:




In 2001 I came to the conclusion I may as well stick with pure C, as I felt that everything useful that C++ gave over C could be obtained by programming in C with discipline. At the time the C++ specification had barely stabilised, so what constituted “standard” C++ was open to interpretation. Implementations were plagued by vendor-specific extensions, which was partly down to the original definition of C++ being botched. At the time some of the compilers I used were boxed ones dating back to the mid-1990s, and as a result I was only interested in properly standardised & and implemented languages, which meant only 1989 C was acceptable to me.

More recent usage

Around 2006 I was assigned teaching labs for C++, which motivated me to once again evaluate the language. This was a combination of realising that C++ had moved on from the 1990's language I remembered, and the shock that it had actually become a much more extensive language. One of the problems was that a lot of C++ compilers, given certain incorrect inputs, would throw out insanely long error messages that would line-wrap even on a full-screen xterm. I suspect this was partly down to how GCC defined some internal types by (I think) templating more general primitives, and the error messages would include information about the inheritance chain for all parameters. Yuk. Back to C.

Ever since my evaluation of C++ has been some variant or other of initial enthusiasm followed by the realisation that I would have to get to grips with a lot of language features I was not interested in. Debugging programs means knowing about language features one does not personally use, which is why I stayed away from C++. I felt that going to proper C++ meant giving up on the down-on-dirty C stuff I liked, but the way C++ did things was a mess compared to the likes of shamelessly more higher-level languages like Java and Python.

Finally won over

Much more recently I have come from the direction of someone used to the built-ins of Python rather than the spartan feel of C, and realised that C++'s STL is actually very featureful. The tipping point was realising it had permutation functionality built-in, and that GCC had gone a long way in clearing up its error messages when I (mis-)wrote some code that used templates for parameter generalisation. Above all was the realisation that there are very few jobs left where use of C can be justified over C++.

I think one factor in all this is having used Python professionally, which was a language I only occasionally used prior to my current job, and even today I don't know it inside-out compared to my C knowledge in my previous company. At the time I felt that putting Python on my CV was at the outer bounds of acceptability, and there are companies out there that expect such an in-depth knowledge, but there is also a tendency for companies to prefer a subset of language features over a free-for-all of anything that compiles is acceptable. One company that tried to head-hunt me (I declined final interview for personal & logistical reasons) mentioned they used a subset of C++ for their kernel-level products.