My current project includes writing for two different mobile operating systems. I had the luxury of enough time to explore the ins and outs of developing a mobile application that runs on multiple platforms.
At the start, I decided to write an example application for each platform. It was something complicated enough to warrant planning efforts.
I wrote the user interface with Cordova (PhoneGap). But had I not been able to use it, the user interface would have had to be coded for each OS individually. This is a big reason for keeping your business logic separate from the UI.
The real business logic was written in Objective C for iPhone, and Java for Android. It was a true port. I figured out ways to get the same thing done on different operating systems.
Such a project demonstrated to me that much time can be spent developing the business logic. So if you are going to support multiple platforms, you will want to do it in a platform-neutral language.
Such pieces needed access to the file system, XML parsing, and file compression.
Now with the project working on both devices, I can see how the trouble of talking to C/C++ routines should be weighed with the trouble of rewriting Objective C and Java. There is not one answer. This should be decided on a per-project basis.
For this project, writing the business logic in C++ would have been best. Once the link is set between the preferred language and C++, more complicated business logic can be done in one language, and easily ported to both platforms. Ongoing maintenance will be made easier as platform agnostic changes will be done in one place.
Yes, it is a pain to get the links set up for the Android NDK. It is a bit easier for iOS. Windows phone may be on the horizon as well.
Even with C/C++, you are forced to think about platform specific and platform agnostic code. The problem does not go away completely. But even with small projects such as this one, a “toolbox” starts to form. Some of the platform-specific code gets pushed down and hidden in some libraries that could be used on other projects.
In all, it was a great learning experience, and one with assets that I will carry to future projects.
Resource: Click here for a good article to read about writing for multiple platforms.