Learn Once, Write Anywhere
written on Wednesday, February 4, 2015
React is an interesting beast. At first it feels weird, as in "What? I have to mix XML in my JS code? How ugly, can someone please think of the children^Wstandards!", then it gets into you (at least it did for me) and you start enjoying it. It's especially interesting when you have some QML experience: while it's not as declarative as QML, the way it strictly separates mutable state and immutable properties and takes advantage of this separation to automatically render the changed components makes React feels a bit like QML by certain aspects.
I started to follow a bit more closely what was going on in the React world and stumbled a few days ago on this presentation by Tom Occhino, announcing React Native:
In short, Facebook has decoupled React from the DOM and is now using it to build mobile apps. This is not well known mobile-app-embeds-webview approach PhoneGap or Titanium uses: React Native instantiates real, native UI elements, they do not try to emulate them using DOM and CSS.
As Tom Occhino says at 28m30 in the video: their philosophy is not "Write once, run anywhere", but rather "Learn once, write anywhere": they are going to build React bindings for all the platforms they want to support instead of providing cross-platform UI elements which look and behave as close as possible to their native equivalents on the platform your application is running on (the Qt approach). This lets you share all the core, non-visual parts of your application across platforms while providing a native user experience. Others are following a similar "Learn once, write anywhere" approach to mobile app development: Ars Technica reports that Google for example is doing something similar for their Inbox app, using Java as the common language.
The main drawback of React Native approach is of course, that you have to write different UI code for each of the platforms you want to support, but if you are ready to pay this price you get a real native look and feel, while still being able to share lots of code across platforms.
I have always been impressed by how deep Qt goes on the desktop to support OS-specific features, but even on the desktop, there are times where you have to write platform-specific code. Given that there tend to be more differences between mobile OS than between desktop OS, I wonder if the Qt approach is going to continue to be good enough or if having platform-specific code for all UI is the only way to go.