Functional Programming on iOS and Android - Making the impossible ... possible?!?!

2015-04-25 Software-Engineering Functional-Programming Mobile

Beginning of the year we had one of our Microsoft Senior Architects from the GDC (Global Delivery Center) in India with us. Over a couple of pints the obvious happened: I sparked his interest in functional programming and he sparked my interest in F#.

First I made Mono and Emacs work, but then I started to use Xamarin.

Not so much, because I needed a better IDE (Emacs rules :)), but because I got interested in the claim that you can use Xamarin to do Android and iOS cross-platform development with #F.

If you need to develop a mobile application (and these days ... who doesn't :)) your choices are full of compromises. There might be cases, when you can get away with supporting only Android or iOS, but in general you need both. To support both you can ...

  1. Develop two native apps. One in Objective-C and one in Java. This will give you the best user experience. Both apps will be able to take full advantage of the capabilities of the respective device, platform and APIs. BUT ... it is very expensive (two separate teams, two separate skill-sets, programming languages, tool-chains (source code control, ...), ...). This can become a night-mare. Quickly!!! Not even talking about the challenge to keep both versions in sync to ensure that the entire user community gets the same user experience (just imagine you are telling a friend about this cool app (on your iPhone) and he/she installs it (on Android) and it is sh... You will probably not tell anybody else about it (not even the iPhone users), because you are afraid to ruin your reputation).
  2. Use the browser. Safari on iOS and the browser on Android share the same rendering engine: WebKit. Means you can get a pretty good cross-platform experience by implementing a kick-ass web-app. There are a couple of very advanced HTML5, CSS, JavaScript based solutions available that can make you live easier (e.g. Apache Cordova/PhoneGap, FeedHenry, ...). BUT ... when you want access to some more sophisticated APIs (e.g. GPS, Sensors (Accelerators, ...), Bluetooth ... (because as we all know ... everything is better with Bluetooth :))) you can get stuck and you might end up needing to compromise the user experience.
  3. Use a cross-compile platform. Means you write the app once (in a given language) and the iOS and Android app get build from that code base. Two examples are Xamarin (using C# (and F#)) or RoboVM (using Java (and Scala)). 

I am currently taking a look at Option 3 (using Xamarin and C#). My initial exec summary is ...
  • It works!!!
  • The IDE is stable enough to get work done (but has some bugs)
  • You get a lot of benefit out of using one development tool-chain (one IDE, one source-code management solution, one testing framework) and one programming language (it is much easier (and less expensive) for the team to solve problems, because they share the same skills and knowledge and can help each other)
  • The Model (as in MVC) can be shared between the two platforms. The Viewer/Controller code is still platform-specific. On one hand it will allow you to create the best user experience possible. On the other hand it will increase the cost to develop and maintain the app(s).
Next step is to make Rachel's F# Minesweeper work on iOS and Android. I am not saying that F# is better than Scala (for me personally it probably isn't), but getting a development environment up and running that would allow me to develop mobile apps using a functional programming language for iOS and Android sounds appealing.