What is Firefox OS all about?

When I first read about Firefox OS, the ongoing project to make an operating system for phones and tablets that runs entirely in a Firefox browser, I thought: what a marvellously futile idea.

The world isn’t short on niche, provisional, or failed experiments in operating systems for phones: Sailfish, Tizen, webOS, BB10, Ubuntu-for-phones, Meego, (cough) Windows Phone 8… Firefox OS is aimed at low-end phones—just the sort where you’d expect the hardware efficiency and limited data requirements of offline native-code apps to offer a big advantage over the browser. So I was ambivalent about its advantages to the user.

The developer side is interesting, though.

C++, the Portable Choice

Look at the current mainstream phone platforms.

For iOS, the “native” development language and framework is Objective-C with Cocoa. For Android, it is Java. For Windows Phone 7 (I do mean 7, rather than 8) it was C# with Silverlight or XNA frameworks.

These three are totally mutually incompatible. You can’t reuse Objective-C/Cocoa code on Android, you can’t run Java on iOS, and the Windows Phone managed environment was incompatible with both.

But every platform has an embeddable web browser, so besides native apps, there have always been somewhat cross-platform HTML apps—often developed using tools like PhoneGap. These aren’t always popular with users, something widely acknowledged when Facebook rewrote their HTML-based iOS app as a native one.

The tension is that while native apps usually work better than totally cross-platform ones, it is desirable to be able to reuse at least some of an app’s business logic across platforms. So developers have increasingly been shifting business logic from the platforms’ primary languages to C++. Google made increasingly more of the Android frameworks accessible from C++ using the Android NDK; Microsoft switched to C++ as their recommended language when developing for Windows Phone 8. Objective-C apps can incorporate C++, so the same code can serve across all three platforms. (How interesting that C++ should have become the portable choice in preference to Java or C#.)

This situation isn’t wholly satisfactory, not least because C++ is a difficult language to learn to write reliable, comprehensible code in.

The Web Angle

So there may be no successful portable managed runtime for typical apps, but there is a very widely used portable runtime on the web, in the form of Javascript. All the major browser makers have been hammering on Javascript optimisations for some years; it now runs pretty much as fast as managed environments outside the browser do, and it’s become widely accepted as a compilation target for other languages (this page lists over 200 of them). The Firefox developers have formalised this arrangement through asm.js, a subset of Javascript designed for fast execution and intended only to be used as a compilation target.

The final piece in that particular puzzle is Emscripten. This so, so wrong piece of software is a backend for a standard C++ compiler, which compiles C or C++ to Javascript. It includes Javascript libraries that map some widely used C infrastructure (such as OpenGL or sockets) to the browser equivalents (WebGL, WebSockets). The resulting code approaches half the speed of native code—except that work such as 3D rendering happens at full speed, because it’s handled by the same OpenGL stack in either case.

So: we have a code environment (the Javascript target) that is genuinely cross-platform, comparable with managed runtimes like the JVM or CLR for performance (though not as sophisticated in terms of memory management) and supported on every current desktop and mobile device. We have a tool that takes existing portable C++ business logic and compiles it to that target. And now, in the shape of Firefox OS, we have a phone OS on which that environment is the native one.

Now there are still all sorts of holes and potential pitfalls here. But you’ve got to admit, it’s a pretty interesting proposition.

So I bought one of the Firefox OS developer devices to have a look at. In my next post I’ll make a few notes about the current state of the platform, and try to guess whether any non-developer would ever want to use it.

One thought on “What is Firefox OS all about?

Comments are closed.