"Never trust a computer you can't throw out of a window" - Steve Wozniak.

Wednesday, January 4, 2012

Modern Cross Platform Development

Why isn't there a modern technology available for using the same codebase to produce native apps on all of the currently popular platforms - I'm talking iOS (iPhone/iPad/iPod Touch), Android, Windows, Mac and Linux?

That was my original question before I started looking, and since then I've discovered there actually are plenty of new options out there for cross platform development catering for all of the above platforms.

A Brief History of Desktop UI Toolkits

In the 1980's the problem of a cross platform desktop user interface was for the most part solved by the X Window system, known as X11, (1984-) along with one of the first widget toolkits, Motif (1989-), which was built on top of X11. Back then, the dominant platforms used by business were Microsoft Windows and the various flavours of Unix, like Sun Solaris, HP-UX, IBM's AIX etc (later Linux came along and maintained full support for X11 and Motif). Developers who wanted to target multiple platforms such as these had this option of developing one codebase, usually written in C/C++, using X11 and/or Motif. The UI code for the most part could remain the same and the application just needed to be recompiled with the provided X11 libraries.

Since then Motif has pretty much faded into the background and been replaced with newer widget toolkits, still built on top of X11, including Qt (1991-), wxWidgets (1992-) and GTK+ (1998-). These now run on many different platforms and bindings are available for many, many languages, including for their native C or C++.

These three free open source toolkits have been successful for the desktop application case but looking towards mobile and tablet platforms, these toolkits don't currently have the support there to take them into the future.

Probably the C++ based Qt widget toolkit is the most well established way of writing desktop cross platform applications. Smartphone support isn't really there yet, but there is an unofficial port to iOS. Linux's KDE desktop environment is written with the Qt toolkit. Many significant apps have been developed with Qt, including Autodesk Maya, VLC media player, Mathematica, Virtual Box and Skype. Qt is now owned by Nokia (although is still open source), and there was a release of a new version recently (Qt 4.8).

The C-based GTK+ widget toolkit is also a very well established way of writing cross platform desktop apps. Smartphone support isn't there, but there is an unofficial port to HTML5. GTK+ powers Chromium on Linux, the open source forerunner to Google's Chrome browser. The GNOME desktop environment is written with the GTK+ toolkit. The other notable app written with GTK+ is the one that launched the toolkit itself, GIMP, an open source bitmap image editor.

A C++ native mode toolkit that provides a thin abstraction to a platform's native widgets. It was originally developed as a desktop GUI toolkit in the same vein as GTK+ and Qt and support for iOS is still beta. There are a number of notable apps developed with wxWidgets including BitTorrent, Audacity, TortoiseCVS and RapidSVN.

Java and Silverlight

Sun's Java Swing UI Library (1997-) and Microsoft's Silverlight (2007-) were both attempts at "write once, run anywhere" (WORA) technology that provided a rich user interface library. Although technically successful, they failed in their attempt to become the ubiquitous technology that everyone uses to develop UIs. They both attempted to replace the 'native' look of apps developed on a particular platform and instead impose their own look and feel based on graphical primitives, which although being more powerful for developers, users on the whole didn't like.

As Johannes Fahrenkrug discusses here, people actually want to run Windows apps that look like Windows apps, and run MacOS apps that look like MacOS apps. To be fair, the Java Swing UI has actually undergone a lot of advances since it was first released and can now generate apps that do look perfectly native on all desktop platforms. The problem may be however that people's original experience of early Swing apps having a slow and inconsistent UI might have put them off using other Java apps and so contributed to its demise.

In the case of Microsoft's Silverlight and WPF, although not officially dead yet, they are now taking a back seat to newer technologies that were released by Microsoft at the September 2011 Build conference; Windows 8 allow developers to create new style 'Metro' applications by using either web technology (HTML5/JavaScript/CSS) or a traditional language - C#, VB.NET or C/C++ paired up with XAML for describing the UI. There's more detail about this topic on StackOverflow here for those interested.

The Rise of Web Applications and the App Store

The two big changes since the desktop UI toolkit days has been the rise of browser-based web applications and more recently the rise of downloadable apps running on smartphones and tablets such as Apple's iOS (powering the iPod touch, iPhone and iPad devices) along with Google's Android (powering a vast array of different smartphones and tablets from many hardware vendors). Google's recent Chrome OS also deserves a mention for creating an OS around the browser itself. These new class of devices offer a quick method of downloading, paying for and installing apps (often with just one click) and appear in the easy to use 'App Store' on iOS and 'Android Marketplace' on Android.

Microsoft is getting in on the App Store action a little late with its 'Windows Store' for Windows 8, which will be appearing some time in 2012. Its thought by Hal Berenson (a former Distinguished Engineer at Microsoft) that the upcoming Windows Phone 8 OS will be based on the same technology as Windows 8 and hence will unify the development platform for Microsoft's desktop, tablet and smartphone operating systems. This will likely be announced some time in 2012, probably at the same time Microsoft launches the 'Windows Store'. This will mean Windows 8's new 'Metro' style apps on the Windows Store will run on phones, desktops and tablets - something that neither Apple nor Google can lay claim to, just yet. Add in the possibility of an XBox update which adds support for running Metro apps, and you have a huge carrot which will make the unified Windows 8 platform very attractive to both application and game developers.

Choosing Your Platform - Desktop, Web or Mobile Application?

When choosing your platform, if you need full access the underlying file system, or access to hardware devices like serial ports, microphones, webcams, etc, then you may be better off staying with a desktop application. If you need platform independence on top of this then you can go with one of the traditional widget library technologies like wxWidgets, GTK+ or Qt to provide a full cross platform UI solution.

Alternatively, if you don't need so much access to hardware and can remain restricted to the browser, then HTML5 and JavaScript may be the way to go. Browser based web applications have their own set of problems however, including the browser incompatibilities, varying support for the HTML/CSS web standards and the Document Object Model (DOM). In addition, web application development generally makes it harder to create rich UI apps than for desktop or mobile applications. HTML5 will provide massive improvements, but web apps are still running in a browser and so will always remain sandboxed and limited in what they can achieve (no access to file system, serial ports, microphone, webcam, etc.).

The main advantage of the browser app however, and its a massive one, is that its everwhere and supported by every device, so if HTML5 takes off, then it could become the defacto standard for developing apps of any kind, desktop or not. As Jeff Atwood discusses in his seminal blog post All Programming is Web Programming; "the web is the most efficient, most pervasive, most immediate distribution network for software ever created - its almost completely frictionless". As Atwood mentions, more and more users gravitate towards preferring to run their apps inside the browser, on smartphones and on tablets where things 'just work' and there's generally nowhere near as much friction caused by the traditional desktop software setup and update process.

A third option available now is the cross platform mobile development SDK as detailed below (Mono, Appcelerator Titanium, Rhodes, PhoneGap, MoSync, Moai, Corona SDK and JUCE). Smartphone and tablet based applications are taking off, and these SDKs allow you to write once and run on any of these new class of devices, as well as in some cases also being able to run on the traditional desktop. These would seem to offer some of the 'power' of the desktop in terms of native code execution speed and access to hardware functionality, along with the enourmous 'frictionless' benefit that you get when publishing to an app store, where installing an app is literally a one click operation.

The C# based Mono cross platform library allows apps to be built using purely C#. However this is not strictly a cross platform UI library, since each supported platform has its own different set of Mono C# UI libaries, each with their own capabilities. The idea is that you build your software using the MVC (Model View Controller) pattern, so that the Model and Controller components (both written in C#) can be shared across all platforms without any changes. Only the View component needs to be re-written for each platform (again, in C#). Mono targets both mobile and desktop apps, however if you are just looking at developing a desktop application, then Mono probably isn't a big improvement over GTK+ or Qt, after all a well written C++ Library (with a Model and Controller component for example) will enjoy the same capability to be shared across more than one platform if you use Qt or GTK+ and then you wouldn't need a different UI library on each platform to create your view. There are several advantages that Mono has over Qt or GTK+ however - firstly in leveraging a team's existing knowledge (and codebase) of C# which is a popular language. Secondly, being able to target iOS, Android and the browser. Lastly, via Mono's .NET CLR implementation (Common Language Runtime), code is compiled into modules of bytecode, which are binary compatible across all the supported platforms.

There is also an open source library for Mono called MonoGame which lets you port with minimal effort XNA based games (which originally target the .NET platform and run only on Windows Mobile, Windows and XBox) to any of the Mono platforms such as MacOS, Linux, iOS and Android.

An open-source solution which allows you to use web development languages (HTML, JavaScript, CSS, Python and Ruby) to build mobile and desktop apps. App data can be stored in the cloud or on the device, and apps can take full advantage of hardware, particularly camera and video camera capability. Appcelerator apps go through a complex compilation and optimization process which result in it creating apps that look, feel, and perform just like native apps, because you are using native UI components... so an iPhone app developed with Titanium will actually feel like an iPhone app. They also offer an API repository marketplace to buy and sell code to extend Titanium. One of the downloadable components allows you to develop your app using an MVC (Model View Controller) pattern. There is an active developer community Q&A site for Titanium developers which is similar in usage to StackOverflow.

Rhodes is an open source, Ruby-based framework that allows the development of native apps for a wide range of smartphone devices and operating systems. The framework lets you write your code once and use it to quickly build apps for every major smartphone. Apps can take full advantage of available hardware, including GPS and camera, as well as location data. Rhodes enforces a strict MVC (Model View Controller) pattern on your apps. Views are written in HTML5 while Controllers and Models are written in Ruby.

PhoneGap is an open source framework that helps you develop apps for smartphones using web development languages such as JavaScript and HTML5. It also allows for access to hardware features including GPS/location data, accelerometer, camera, sound and more. PhoneGap lets you take a web app, run it in a UIWebView, and through javascript you can access iPhone features such as the camera an accelerometer. This means that it won't necessarily have the look and feel of a native app (like the other cross platform SDKs listed here). The idea is that you develop your web app like you normally do, and then use PhoneGap to 'bridge the gap' to the phone, and give you access to phone's hardware, that traditionally you couldn't access from a web-only app.

The MoSync Mobile SDK is a cross-platform mobile application development SDK which allows the development of native apps. Free open-source, it is based on C++ but allows development also in HTML5 and JavaScript. MoSync provides access to a wide range of underlying device functionality, via a C++ SDK or optionally via JavaScript. It requires probably a greater degree of software skill from the developer, but in principle can enable a rich variety of different kinds of application.

Although intended to be a mobile game development SDK, I think it deserves a mention here due to its unique scripted approach to cross platform development. Games developed with Moai run on iOS and Android as well as the Chrome Web Store, Windows, Mac and Linux. Designed to be programmed with the Lua scripting language, Moai is designed for experienced game developers who wish to use Lua for mobile development. The Moai framework itself is written in C++ and is intended to be called from the Lua scripting language, but can also be called from any other language supported by the host platform. The Lua script is run as interpreted byte code, but since very few Lua instructions are processed among all the input handling, this means that rendering, animation, collision detection, and physics math runs natively. Moai's physics engine for example is the Box2D open source C++ library. Moai is free and open source, however to build apps for iOS devices you'll need the iOS SDK and the Xcode IDE (presumably running on MacOS) and be a member of the Apple iOS developer program (US$99/year). To build apps for Android you'll need the Android SDK, the Eclipse IDE and an Android device.

A similar toolkit to Moai in that its primarily aimed at game developers, and apps are written with the Lua scripting language. Corona SDK was developed by two former Adobe mobile engineers and has been in development since 2007. It features a proprietary OpenGL-ES rendering engine, which allows for full hardware acceleration of graphics, including sprites that animate at full GPU speed. The Corona physics engine is built around Box2D as with Moai. Its free to try Corona and run your apps in a simulator on your desktop computer, but to build an app and publish it to an App Store, you'll need to pay a yearly subscription fee (of either US$199 per year for Android or iOS or the premium subscription of US$349 for all platforms). Your apps are built "in the cloud" on Corona's server. Note that if you are developing for iOS you'll still need to pay the yearly Apple iOS developer program fee which is currently US$99. There seems to be extensive documentation available for Corona and an active developer community forum. There has been a recent push to promote Corona for use not only for developing games but also for general apps and also interactive ebooks.

JUCE is an all-encompassing C++ class library for developing cross-platform software. Its designed to contain everything you're likely to need to create most applications, and is particularly well-suited for building highly-customised GUIs, and for handling graphics and sound. JUCE is developed by Raw Material Software and consists of a small team of developers based in London, England, founded by Julian Storer in 1999, who is still the primary developer today. It would probably be best suited to experienced C++ developers. Julian Storer himself is a professional C++ coder with over 15 years of C++ experience; he takes pride in the fact the source for JUCE is literate, coherent, cross-platform and high quality. Adding JUCE to your C++ application is very simple - the easiest way involves simply including juce.h in your files and adding a single .cpp file to your project. No need to compile any libraries or worry about dependencies.

@Akshat Jain; I'm really referring to Mono's 'Monotouch for iOS' and 'Mono for Android' frameworks which are libraries for developing native UI apps using C#. But yes, the original Mono is a .NET CLR (common language runtime) implementation.

I've recently tested HTML5-based solutions (Phonegap, Rhodes) and the performance, even for example applications, was terrible. A colleague from my workplace summarized it nicely: "I haven't seen any Phonegap app that doesn't piss me off because of poor performance".

Titanium Appcelerator performance was fine (mostly because it used native UI controls instead of HTML5 crap), but the downside was using non-standard tools, which are significantly worse than Eclipse/XCode.

Compared to Qt MoSync is a bad joke, so I don't see any benefits from using it.

Qt can be also used for writing Symbian^3/Meego apps, and there is quite advanced port for Android called Necessitas. AFAIK the iOS port is working fine, but there are some legal issues with publishing Qt-based application to AppStore. I also remember reading about planned support for Qt on Blackberry, which means that Qt have a good chance of covering all mobile platforms except Windows Phone 7.

@Everybody - The write-up on Mono here is quite good, better than most, but there are a few gaps:

First, Mono can also be used to target the web which was not mentioned. You can use any of a number of web frameworks including ASP.NET (WebForms or MVC), Nancy, or Manos. Most of the Mono applications I have written were web apps.

Second, Mono can be used to create Windows desktop apps as well. It also allows you to write applications that use .NET on Windows and Mono everywhere else using the same code and even compiled binaries (assemblies as .NET calls them). Mono is a cross-platform implementation of .NET but you could also think of it as .NET being an implementation of Mono that is only found on Windows. Your Mono app can run on either implementation.

Third, although Mono does not target Windows Phone 7, you can share your non-UI code between Windows Phone 7 and Mono. So, choosing Mono as your cross-platform strategy makes it easy to add Windows Phone 7 to the mix.

Forth, I somewhat disagree with the advice that "you may as well just hook directly into the native UI libraries on each platform to create your view". I have two-reasons:

1) The big advantage (for me at least) of a platform like Mono is that the "compiled" code is portable. I can, for example, provide a single binary that an end-user can run on any supported platform. A single executable could even call one UI layer when run on one platform and another UI layer when called elsewhere. For back-end stuff I can use the same library in multiple projects without even recompiling. In fact, I can do this even if I do not have access to the source code (like with commercial components).

2) When you use Mono, you are calling into the native libraries which is why the UI layer code is different on each platform. For example, on Linux the most common UI for Mono apps is GTK+ which is described in the post above. On iOS, applications are even compiled down completely to native machine code before submission to the app store. Mono massages the API on each platform to be more natural to C# programmers but the abstraction is very thin and the full native toolkit is available.

As somebody else noted, choosing Mono is somewhat independent of choosing what UI to use or even what cross-platform UI to use. For example, there are Mono apps that use GTK+ to share the UI code across Linux, Windows, and Mac (like Banshee, MonoDevelop, and Tomboy do). I can write Mono apps that use PhoneGap, QT, Windows Forms or other options that support multiple-platforms as well. The preference for coding a different UI for each platform is a philosophical one promoted by Xamarin (the primary company behind Mono) in their commercial products.

@Justin thanks for your indepth comments on Mono, I'll incorporate some of your input in my post which will help to clarify things. I forgot to mention about Mono being able to develop web apps using MVC - a fair point since the model and controller logic can be shared in this case through web, desktop and mobile app development. Although there's nothing to stop you developing a Microsoft MVC web app either, instead of Mono MVC. Binary compatibility over platforms is a big win also, as you mention.

its one language with multiple targets. especially useful for those who are tired of learning multiple languages and/or have dumped a lot of time doing flash development. since it has a javascript target, you can even target nodejs as well.

jQuerymobile has announced AC as a JQM dev platform and here's a case study that Phonegap did on them : http://phonegap.com/case_study/phonegap-application-craft-pain-free-mobile-app-development/

In summary, it's a cloud-based dev platform that does mobile (all important platforms) and desktop on an equal footing. It's got an IDE that does drag-and-drop / WYSIWYG UI building as well as code editing. I guess you could describe it as Visual Basic in the Cloud, but Javascript not Basic. Widget based like VB was, extensible. Open Source with free platform offering.

Thanks for the suggestions, keep them coming. I'm going to update the article with a few other toolkits I've heard about in the last couple of days. Regarding Haxe - it looks interesting, sort of like a 'meta-language' but I'm not sure if its a cross platform tool per se.

Both are geared at game development and cross-platform OpenGL / ES support, so if you are doing a full screen game then these frameworks will help you hit all desktop and mobile targets. The Proton SDK is a component oriented effort.

I'm the author of TyphonRT which is a Java cross-platform runtime and SDK bringing that promise of write once run anywhere back to Java (for the most part.. ;P). My efforts run across the J2SE and all Android versions 1.5+ and one can write a full screen OpenGL/ES app that can run on all platforms, but it's also possible to target each platforms particular GUI libraries. TyphonRT is a modern effort insofar that it is constructed in a highly data oriented design / component architecture fashion and the core runtime and SDK is split into over 700 individual components allowing reconfiguration for many vertical app categories besides game development. TyphonRT also fixes a lot of the underlying performance problems with Java on Android that infect various versions of Android providing a better runtime for all apps.

Also a lot of thought has gone into intelligently providing a bidirectional interface to JVM languages making interoperability between the Java layer and the JVM language layer much easier than traditional OOP. Scala is the first JVM language receiving full support with TyphonRT.

As things go though since my efforts are taking a novel approach platform finalization is pending and a release will be out later this year. I'm also taking a very strict view on quality and architecture finalization before release.

Another Java honorable mention is LibGDX which is a game development centered Java framework for cross-platform game dev. It's OOP based, but out now and solid w/ updates ongoing. www.libgdx.org

Where's the love for Adobe AIR? I've got a product (SouthernTouch Spades) written with Flash Builder 4.6 as an Adobe AIR 3.1 ActionScript project. My game is available on Android, iOS and QNX (the BlackBerry PlayBook). I could also package the app as a desktop game for both the Mac and Windows systems.

Yes, It is quite strange that Adobe AIR is so non spoken of. There is a reason it became so dominant in the past.. (On the web) These reasons have not gone away.Everyone seems to want to re-invent the wheel. AIR appears a casualty of "Not Cool" because Steve Jobs, a man know for telling untruths that suite him and Apple, decided to kill it of as it threatened his business models.

It a shame as I still have not seen any cross platform technology with the wide range of feature sets and supported platforms as AIR/Flash.

I'm probably going to go against the trend and stick with it as I simply cannot find a replacement. (Apart from hiring more developers and spending 2x as much on my development)I'm hoping that it will swing around and become cool again as.. Everything I have seen so far.. simply does not answer my needs.. and I imagine many others.

Please seem to forget its not all about games.. Its not all about writing for Table only. Computers and being able to run your App on a PC/Mac as well as on your tablet is a must.

Green-screen terminal systems were popular in the 80's before the rise of client/server computing, and Windows(TM). IBM's 3270 is one example. It was a pretty big market. SunOS was the Sun 80's offering, Solaris came in 92/93.

Qt on iOS? I don't think so, there's been sporadic proofs of concept, but there is little *truly viable* for developers to use today - http://sourceforge.net/projects/qt-iphone/forums/forum/1168055/topic/4898643. Much of QTland is truly terrible in terms of searchability though so I could be wrong.

There's also "Illumination Software Creator" which works a little differently. It produces native code for all the platforms it supports (Windows/MacOS/Linux/iOS/Android/HTML5/...) which you then compile using the platform's own tools.

If you're going to mention Moai, you should mention Corona from Ansca Mobile. Also based on Lua, also for games, but they are making a push to make it just as good for business apps as it is for games.

There exists an open source project that is moving into phone apps and all — the venerable Freepascal, with an IDE for command-line tools, and the Lazarus IDE for consloe and GUI applications. From their web site:---

“Free Pascal (aka FPK Pascal) is a 32 and 64 bit professional Pascal compiler. It is available for different processors: Intel x86, Amd64/x86_64, PowerPC, PowerPC64, Sparc, ARM. The discontinued 1.0 version also supports the Motorola 680×0. The following operating systems are supported: Linux, FreeBSD, Haiku, Mac OS X/Darwin, DOS, Win32, Win64, WinCE, OS/2, Netware (libc and classic) and MorphOS.”

” The FPC backend for the Java Virtual Machine (JVM) generates Java byte code that conforms to the specifications of the JDK 1.5 (and later). While not all FPC language features work when targeting the JVM, most do and we have done our best to introduce as few differences as possible.” and much more…

Some current Links…Aim at this release perhaps :http://www.pilotlogic.com/sitejoom/index.php/codetyphon

But look back to here :http://freepascal.org/Lazarus IDE : http://lazarus.freepascal.org/

Someone already mentioned Corona SDK. I'll second that mention (disclosure: I work for Ansca Mobile, makers of Corona). Corona lets developers build rich apps for iOS and Android using Lua. We have tens of thousands of developers building games and, more and more, business-type apps as well.

@dvdm RE: Pyxis mobile platform - I've just done a bit of investigation of this platform - it looks interesting, but it seems that its more of a brandable runtime environment which is 'configured' not coded and doesn't generate independent native apps, which the other toolkits I've listed can do. For your app to run, you need to be running both an Appication server (Microsoft IIS based) and a Microsoft SQL Server instance which it can connect to. Its considered to be primarily for enterprise mobile app development.

HiThanks for a good list. I just want to clarify. MoSync use HTML5 and JavaScript as well as C/C++.Before MoSync 2,7 and soon 3.0, MoSync was mainly used by C/C++ developers to create powerful cross-platform applications. Now MoSync users can use standard HTML5 or C/C++ or a combination of both.You can boost your HTML5 applications(even PhoneGap apps) with native features like notification, sms and Native UI. Our just generate applications from your HTML5/JavaScript project in minutes to iOS, Android and Windows Phone 7.

Can you add Moscrif to that list? It supports all the main platforms, is free to download and uses the all-popular JavaScript, so no need to learn Lua or other languages. More information - http://moscrif.com

Not having mobile programming skills in Objective C, Java, Javascript, or other languages no longer has to be a roadblock to developing mobile apps. All developers can now build, test and deliver data rich, native apps quickly and easily without any mobile programming skills required. More info is here: http://bit.ly/YN5utC

XOJO - http://www.xojo.com is a cross platform development language/tool worthy to be listed on this page as it supports all devices. Its language is similar to old vb6, unfortunately it lacks a real mvc library to open it up to enterprise level style development