So You Want to Build a Mobile App? (hint: Use NativeScript)

According to some research the number of mobile devices in the world passed the world’s population in late 2014 at somewhere over 7.2 billion devices. While not all of those devices represent a mobile phone in a person’s hand, that number is still staggering and larger today than in was then. Add to that the number of tablets shipped in the last few years and you can see why every company from Amazon to your favorite local restaurant is clamoring for a mobile app to represent their business.

However, building a mobile application that works on multiple platforms has traditionally been very expensive. The two dominant mobile operating systems, Android and iOS, are completely different and require specialized experience in each to build an application. The cost associated with not only maintaining separate development teams, but ensuring that your application provides the same user experience on both platforms can get astronomical. Many businesses just can’t afford that kind of financial commitment.

Enter NativeScript

NativeScript represents a fundamental shift in mobile app development because it allows one code base to be used to build a version of the application for both Android and iOS (with Windows universal apps to be supported soon). If you’ve been around the mobile development space in the past, you’re probably saying to yourself that you’ve heard that siren song before. Likely you are thinking of PhoneGap or Titanium. While the concept of building a cross-platform application from a single code base is not a new one, the approach that NativeScript takes versus these other options is.

NativeScript apps are, well, native. Rather than using traditional web development technologies and packaging them inside a web view container to approximate a native application, NativeScript uses an embedded javascript virtual machine (V8 on Android and JavascriptCore on iOS) to execute your application code and provide access to the native OS APIs. That sounds mind-bending at first, but it boils down to your code being much closer to the “bare metal” of the device and having to go through less “layers” of abstraction to get executed.

Additionally, since NativeScript is accessing native OS APIs, when a new version of the OS is released, you get immediate access to any new features. Let that soak in for a minute — day zero access to new OS features and APIs. You don’t have to wait for someone to write a “wrapper” to a new feature before you can use it in your code (or write a wrapper yourself).

Getting Platform Specific

NativeScript ships with a library of user interface components that render differently depending on what platform the application is running on. Things like buttons, text fields, switches, sliders and more are included to make it easy for your application to look like any other native application running on the same platform. These components are platform-aware and generally simply provide a common, abstracted interface to the underlying platform. Also included are platform-specific attributes that let you further configure their behavior for the platform where your application is currently running.

However, as most developers know, there are times when cross-platform abstractions simply don’t provide what you need in your applications and you must write code that is specific to a particular platform. In those situations, NativeScript allows you to write multiple, platform-specific versions of your components that are dynamically executed based on the OS of the device being used. This allows you to continue to use one code base for your application while being able to tailor the behavior of your application to take full advantage of the capabilities of each platform.

What This Means to the Developer

The bottom line is that if you already know Javascript and HTML, your learning curve to being able to write cross-platform mobile applications is significantly shorter than learning how to develop directly for Android, iOS and/or Windows. No longer do you need to learn up to three entirely new languages and ecosystems. If you have been developing applications with NodeJS, NativeScript will feel even more familiar. NativeScript can use the same RequireJS syntax for dependency injection as you have been used to in NodeJS applications. Add in the ability to leverage nearly any library published to NPM and your development cycle speeds up even more.

If your interest has been stirred, NativeScript has published an excellent Getting Started Guide that you can walk through and experience the magic first-hand. You can also follow me on Twitter or Medium to get notified about upcoming NativeScript articles and tutorials.

Code Assist for NativeScript views in WebStorm

For the last few weeks I’ve been spending a bit of my spare time getting up to speed on a relatively new player in the mobile application space named NativeScript. NativeScript lets you write cross-platform mobile applications in TypeScript (or plain javascript if you prefer), a subset of CSS and XML files for views.

One of the struggles I have when I’m learning a new technology is that I’m very slow because I’m constantly switching to a browser to look up syntax, attributes and other language specifics before the mental “muscle memory” is formed. Good IDE support helps with this as the IDE makes suggestions that many times can let you find what you need without having to switch to a browser and look it up. Unfortunately, NativeScript is SO new that support from many today’s popular IDEs isn’t available yet.

Read More