Thursday, August 30, 2018

The Ever Fragmenting World of Mobile

In the late 2000's Apple and Google ushered in the age of mobile. The features on these devices, like touchscreens, Bluetooth and cameras, empowered early mobile developers to create new experiences for end users. As consumers embraced the new devices, businesses and developers discovered the utility of giving users instant access to services and products on their ever present phones.

Years later, Android and iOS phones are ubiquitous. Not only have they been successful in the US, the low cost of mobile devices have allowed them to take root in developing markets where more expensive computers could not penetrate.
The OS Market Share, dominated by Android and Apple
Chart from StatCounter Global Stats
Even though the Android and iOS OSs dominate the mobile market, the technology used to develop these apps is fragmented and ever changing. This post offers an abridged history of mobile development and highlights the trends I think will prevail.

The Mobile Web

In the first year of the iPhone (2007), Apple's answer to building mobile applications was web apps. While Steve Jobs was initially convinced of the decision, the backlash from users forced Apple's hand, and the next year Apple released an official SDK and app store.

But during that year, responsive web app development tools and frameworks rose to the challenge. They offered a cheap way to develop web applications which could work on both mobile and web. The ease of cross platform apps was (and still is) a business's dream, as it is easy to triple the cost of development by maintaining two mobile applications in addition to a web app.

When the opportunity to develop official native apps came in 2008, many developers were able to build and gain recognition for powerful apps which took advantage of native apis. Over the next few years, businesses would migrate to native development as well to take advantage of better performance and richer device apis.

Native Cross Platform development

If web apps could not provide enough power for cross platform apps, then a new solution would have to be found. The challenge of writing a single native app for iOS and Android is each OS processes different types of code. Android runs dalvik bytecode while iOS runs machine code. To create an app which could run on both platforms, developers knew they needed to compile their code down to distinct packages for Android and iOS.

I had trouble finding the very first solution but by 2011 there were already multiple tools available for native mobile cross-platform development (if you know which was first to market, please share it). The two which I have been most aware of are Xamarin and Unity, both which were created before the world of mobile and have endured, in my opinion, due to their larger visions beyond mobile. Unity was created in 2004 and is targeted towards multi platform game developers. It was one of the first to provide development support for the iPhone and has not relented in adding support for new platforms which emerge, such as VR. Xamarin was born in the early 2000's and had a focus on making .Net development accessible to to developers on all platforms. When it was created, it focused on introducing it to Unix, but it eventually expanded to encompass mobile application development as well.

Both of these platforms managed to offer a solution to the problem of cross platform development and opened mobile development to new languages. Today there is a long list of cross platform development tools each with its own target developer audience.

Even as "compile to native" technologies matured, web technologies refused to disappear from the mobile development sphere. In 2009 PhoneGap was released as a framework for developing mobile apps with web technologies. The application is written with web technologies, packaged in a native app, and run in a WebView. Additional native functionality can be accessed via a plugin system which offers javascript apis to access native functionality.

Apple gave the platform a boost by approving it (ensuring phone gap applications would not be removed from the app store). The tool was purchased by Adobe and submitted to the Apache foundation in 2012 as Apache Cordova. Since then many native features have been added to Cordova and multiple versions of the software have been released, such as Adobe PhoneGap and Ionic.

Current Cordova features for Android and iPhone (from Wikipedia
All of these tools offered a promise of powerful native performance and access to native apis, paired with cross-platform development. However, developers were also frustrated by the added layer of abstraction between the themselves and the native code. This layer introduces a new (often cryptic) class of bugs, and leaves developers at the mercy of platform maintainers to expose new features released by Google and Apple.

Reinvigorating the Native languages

As the modern mobile age closed in on it's first decade, both Objective-C and Java were notorious for their verbosity and had not kept up with the newer trends in programming. In an attempt to make development cleaner for an event driven environment, Apple released Swift in 2014. A similar introduction took place for Android with Kotlin in 2017, a shift that was driven by the developer community and adopted by Google.

These new languages offer more succinct syntax and greater type safety to make development easier and less error prone for new and old developers alike. They also introduced functional programming paradigms which made asynchronous event handling and data manipulation easier for developers to grok.

These new languages have gained popularity and are both ranked in the TIOBE index (Swift at 11 and Kotlin at 43 circa 8/2018). Even with their modernized languages, native iOS and Android development did not kill cross platform development. Native development can be overwhelming due to their frameworks; state and UI management are messy, and platform quirks (ex the Android life-cycle) muddle you ability to architect your application. On top of that, the economic advantages of having one codebase to support are still a big draw away from native development.

Flutter & React Native

In 2015, we were introduced to React Native by Facebook, a framework for building native apps using the same patterns as React.js. For those of you unfamiliar with React, you can learn the concepts here or try building a small React Native app using this demo I helped put together. The big things it has to offer are simplified state + data management (especially when you add redux), better performance than an app in a WebView, and a simple learning curve for web developers.

React Native is written in JavaScript, similar to Cordova. But whereas Cordova ran the app logic and UI inside of a WebView, React Native runs your app logic inside of a JS interpreter and takes the UIs it generates, and renders it using native Android and iOS views. This results in more responsive UIs which are not constrained by performance of WebViews. That said, React Native does come with some performance issues of its own, most of which occur with large UIs of heterogeneous content.

Google, not to be forgotten, offers a fully native analog to React Native in the form of Flutter. Flutter follows the same component pattern as React with a nearly identical flow for state management. However, Flutter apps are compiled to fully native code (no running in a WebView like React Native), allegedly allowing it to provide better performance. If you are interested in learning more about Flutter you can read about my experience using it here.

Progressive Web Apps (Return of the Mobile Web)

In 2015 the term "Progressive Web App" was coined, and the ghost of Steve Jobs smiled (or perhaps he smirked).

Progressive web apps are normal web applications published on the web with some additional metadata for mobile devices. When a browser visits the page it will use that metadata to present a native app experience with color and icon branding. After enough usage the browser will prompt the user to save the app to their desktop using the app icon and title from the metadata. If the user chooses to do so, they can launch the PWA, even when offline, and it will run in the browser but appear like a native application. You can see an example PWA by pokedex.org below.



There are two key difference between the launch of the iPhone and now. The first is browser performance is consistently improving, allowing complex web apps to behave smoothly. I found it difficult to find benchmarks of browser versions over time but I found that Lifehacker was doing performance tests from 2010 to 2013. Based on their benchmarks from March of 2011 to January of 2013 the fastest cold boot time decreased by 50% and the highest JavaScript runs per second doubled. These differences are just meant to illustrate the improving performance, if anyone puts together a more robust study of multiple browser versions on the same hardware platform I would love to share it!

The second difference, is browsers are becoming more invested in adding PWA features and there is a standardization of APIs for these features. You can see a comprehensive list of supported PWA features by browser here.

Google has established itself as a steward of PWA technology, developing tools like lighthouse for testing your site for PWA readiness and adding many features for native apis to Chrome, like web Bluetooth. And Apple is finally taking steps towards achieving Steve Job's vision. This March they announced their support for service workers in Safari and enabled support for PWAs to be saved to an iOS device just like on Android. While the features supported are limited compared to Google's, they are growing.

PWAs, while still in their early adolescence, can realize the vision of frictionless cross platform development using the web, with browsers taking the brunt of supporting native features.

Conclusion

In my opinion, as better options for cross platform development emerge, native mobile application development is going to decrease in demand. The options for cross platform development that we see today are becoming more full featured and can cover a greater breadth of use cases.

I personally believe that most lightweight applications for consuming information (ex. the news or ecommerce) will be progressive web apps. Meanwhile, solutions like Flutter, Xamarin, and React Native can be used for more complex apps by those trying to minimize mobile development costs or developers trying to use their skills from another language in the mobile sphere. Perhaps even Kotlin will get native compilation support and some clever developer will make it possible to build iOS apps with it.

I do think that Swift and Kotlin will continue to play an important part in the mobile scene. We still need native modules for these cross platform solutions to open up new native apis to those developers. In addition, there will be apps that will need to be written in native code to meet high performance requirements and allow access to the newest and greatest mobile apis.

Thanks for joining me in this look back at mobile development history. If you have any important events that I missed or thoughts about the mobile landscape that this piece sparked, please share them below!

0 comments:

Post a Comment