Marmalade’s senior SDK engineer Andrew Parker talks us through plans to support the latest version of the widely-used language

Made With Marmalade: Five reasons to try C++11

Why use C++11? 

Since its earliest days, Marmalade has used C++ as its core language and, time and again, performance, portability and popularity have been the defining characteristics of this language.

With the addition of C++11 support, we’re making sure that our developers can leverage new language features that make their code more expressive, less prone to bugs and easier to maintain.

Marmalade has always been open and flexible, allowing our users to take advantage of great open source software and with C++11 support there’s now the option to incorporate modern libraries and frameworks that make use of C++11. 

Our goal at Marmalade is that you should never have to #ifdef your code to cater for compiler-specific behaviours and gotchas.

C++11 was ratified as a standard years ago. Why is Marmalade now able to offer support for it?

Just because the standard was ratified, it didn’t suddenly mean you had a weath of new tools at your disposal. Creating a new standard is one thing, implementing it is another.

In order for vendors to offer C++11 environments, they needed to update their C++ libraries – source code and headers – as well as update their compilers and runtimes. Sadly this is not something that’s quick to do.

We also needed all of the compilers we use and underlying platforms to support C++11. We believe we’re now at a time where the common support amongst all our supported platforms is good enough to make supporting C++11 both feasible and worthwhile to our developers.

So what new features are the most interesting?

I can’t talk about everything in C++11 here, so instead, here are five of my favourite features of C++11. 

1. Move semantics and r-value references
This one is for the optimisers and performance geeks. Move semantics cut down a huge number of unnecessary constructor calls. Compilers have tried to optimise unnecessary calls away but now the language gives you a way to ensure those disappear. 

At a previous company, we saw a ten per cent performance increase in string heavy parts of our library when we started using a compiler with move semantics 

2. Threads are no longer the elephant in the room
The C++ standard finally acknowledges the existence of threads. Not only do you get a standard API for manipulating threads – std::thread and std::atomic – but those threads now have a rule book to play by. It means we have portable threading code at long last.

3. Smart pointers and the death of auto_ptr
Finally, we can stop importing Boost just to handle pointers. Pretty much everyone coding in C++ will have had to address the issue of smart pointers. Most major C++ codebases will use one form or another of them. Now they’re here, out of the box.

And you can take auto_ptr off to the big farm out in the countryside: unique_ptr is the new kid in town – although its real power comes from move semantics.

4. Delegating constructors
For the fans of DRY – of which I am one – come delegating constructors. Code maintainability just got a little easier. 

5. Type traits
Perhaps one for meta-programmers, but type_traits can let you do some pretty cool tricks with templating. Alternatively, you can use them to make life miserable for your fellow developers when trying to understand your code. 

Are there any downsides to using C++11?

Like anything that’s fun in life, there are always downsides. For C++11 in Marmalade, the major headaches are with Windows support. The compilers in Visual Studio are not C++11 compliant and also the
compiler is far from GNU compliant. Getting libc++ to work with Windows has been tricky.

There are a few features that won’t work right now. Over time we will endeavour to reduce that set of problems, and hopefully as Microsoft Visual C++ improves its C++11 support, many of these issues will go away.

Right now, the set of features that do work is still vast and hopefully enough to let you build performant C++ applications more quickly with modern coding practices. 

How can developers get involved?

We’re running an open beta: just head over to bit.ly/1ESa8lB. You can also find out more at www.madewithmarmalade.com

About MCV Staff

Check Also

The shortlist for the 2024 MCV/DEVELOP Awards!

After carefully considering the many hundreds of nominations, we have a shortlist! Voting on the winners will begin soon, ahead of the awards ceremony on June 20th