iangilham.com

By on

software cplusplus learning

My new job includes C++ development so I’ve spent much of the last few weeks working through a text book and various tutorials as I pick up the syntax and learn about some of the concepts not exposed by the other languages I have worked with.

Coming from a Java and C# background, I’ve never really needed to understand pointers or the finer details of memory management before. Now that I am getting a feel for C++, I have much more insight into some of the design decisions of other languages and am beginning to appreciate the amount of explicit control that the language provides. It has been particularly illuminating to see how simple search and sort algorithms work using pointer-based arrays.

All code from my learning project is in the ccplayground project on BitBucket (https://bitbucket.org/igilham/ccplayground).

Functional Programming

My first bit of ‘real’ C++ code was a little experiment in translating some traditional functional programming concepts into C++. While a truly functional style is inefficient, I wanted to see how effectively I could implement [filter](http://en.wikipedia.org/wiki/Filter_(higher-order_function), [map](http://en.wikipedia.org/wiki/Map_(higher-order_function) and fold/reduce functions with the facilities provided.

Containers

One of the exercises I have been using to learn C++ is to implement a few basic container classes. I started with a linked list from the text book then added a few variations. I have found that private inheritance, when read as “implemented in terms of” provides a powerful way to expose a subset of a class’s methods without writing much code. I have used my linked list to implement a stack and queue without the extra code required to achieve the same with simple composition, as I would have done in Java.

Next steps

I am getting to the stage where there is an uncomfortable amount of code in the ccplayground project without proper tests. That is, I haven’t yet got around to learning and using a unit test framework for the language. I think my path is clear.