Why create mobile apps in C++

by Apr 5, 2018

There are a wide variety of languages used for mobile development: Swift, Objective C, Java, Kotlin, Delphi, C#, and C++. What are the reasons to choose C++?

Consider a language along three axes: expressiveness, conciseness, and performance.

  • An expressive language allows you to easily write powerful concepts in code. It is easy to manipulate data in useful ways. ‘Data’ is any variable(s) your app uses and powerful means manipulation in non-trivial ways, whether that mutates the data or merely operates on it.
  • A concise language allows you to express yourself quickly. You type less. It is clear an unambiguous, readable and understandable, yet short and taking up less space onscreen and fewer keystrokes to implement.
  • A performant language compiles to fast code. More, the language design makes it easy to write code that will be well optimized.

C++ occupies an unusual position among languages. It is powerful: code can be expressive, concise, and performant all at once. This is unusual. Languages can be expressive but non-concise, expressive but not performant, performant but low-level and unexpressive in that it takes a lot of code to write complex behaviour, and so forth. C++ has always had a reputation for performance, but especially in recent years with modern C++ (’11 and newer) the language allows powerful expressions and algorithms in very tightly compiled code.

Finally, there are a large number of useful libraries written in C++. From app basics like JSON through to maths like fast fourier transforms or linear algebra to image processing to data recognition to graphics, there’s C++ code to do it.

Thus, C++ tends to be the choice when a developer wants something that runs fast, allows good data manipulation, and is concise onscreen. It’s also used when you want to make use of third party libraries. C++ used for games: performant, and they may have a lot of code, and pull in many common libraries. It’s used for key desktop apps: performant, lots of code, and unusual data manipulation (Explorer does interesting things with files and COM objects. Word manipulates text, layouts, references and more.) And as it happens, mobile fits this perfectly.

What’s important for a mobile app?

Mobile app development has a few key differences to typical desktop or server app development:

  • Energy usage is important. People uninstall apps that eat their battery.
  • Performance is important. There are a decent CPUs in today’s top end phones and tablets, but they’re still limited by a mobile power supply (so you don’t want to spend more cycles than you need to) and a vast number of phones around the world use much lower spec hardware.
  • A very different UI.

A UI is not necessarily something you tie to a language. (C++Builder has great UI tools for cross-platform UI, without losing the benefits of using C++.) The other two are worth considering in more depth, because both points say the same thing in different ways: using less CPU cycles for the same work is better. It’s better for the user, because they see their app running faster; it’s better for the device, because it spends less energy. You always want well optimized code on a mobile device.

What does that mean for a choice of language? It means you want a language that optimizes and runs natively, of course, but also means you want a language that makes it easy to write code that will be well optimized. Here, we circle back to expressiveness and conciseness: write powerful concepts in small clear code that runs fast on the target device.

That’s C++.