Dev Watch

Blog archive

Changing of the JavaScript Guard

Who would have foreseen the ongoing transformation of the lowly JavaScript Web scripting language to the go-to coding choice for native mobile apps and maybe even the desktop?

Coders from Facebook to Telerik are joining open source enthusiasts and traditional JavaScript-oriented vendors such as Appcelerator (Titanium) and Adobe (PhoneGap) to apply JavaScript in new and innovative ways for native mobile app development.

Along the way, they're breaking longstanding "best practice" rules for the 20-year-old language, stirring up the JavaScript community and forcing devs to reconsider how they structure and create JavaScript projects.

And from the reaction of some traditionalists, it promises to be a bumpy ride.

"First impressions were pretty skeptical," said Facebook's Tom Occhino in recalling his company's open sourcing of React.js, a new approach to JavaScript Web development, in 2013.

"Everybody kind of tuned out, they just shut off" when presented with a slide that showed a definite non-separation of concerns in some example code. "They were like, 'I don't know what that is; I've never seen that.' They took to Twitter. What they told us was that we'd taken a 'huge step backwards' in terms of the maintainability of our code, simply because we were embedding our markup, or our HTML, inside of our JavaScript. This was crazy. 'You can't do that!' " he recalled of the reaction.

Audience Reaction to Including CSS in JavaScript
[Click on image for larger view.] Audience Reaction to Including CSS in JavaScript (source: Facebook video)

Occhino was speaking in a keynote address at Facebook's React.js Conference 2015, wherein he introduced React Native, an upcoming approach that leverages an optional JavaScript variant called JSX to target iOS and Android apps. Instead of "write once, run anywhere" -- which is a "pipe dream," Occhino said -- it's "learn once, write anywhere."

"What is interesting is the language, JavaScript!" said one commenter on the ADTmag article about React Native. "Once thought of as a tool for purely Web design [it] has matured into a product worth considering coding applications in."

However, some developers were skeptical about React Native, too.

"So ... a JavaScript interface to a server that creates native views," read one comment on a Hacker News thread. "I don't get it, what is all the hype about? You've got an extra layer and level of abstraction (read: complexity) in your pipeline. I don't see how you can abstract away the idioms of a platform -- they're native. 'Write once, run everywhere' has failed time and time again. So marketing changed its tune to 'Learn once, run everywhere' and now people are gushing how HUGE this is?"

Others, however, expressed enthusiasm about the project and welcomed it -- even the established Appcelerator, which uses a somewhat different approach to coding native mobile apps with JavaScript.

"Welcome to the club!" said Appcelerator's Chris Bowley in a tongue-in-cheek blog post titled "Our Reaction to React Native (Or: Why JavaScript Will Rule the Mobile World)."

However, Bowley's main point was that Appcelerator has already been doing many of the React Native techniques. "There's always something to learn from other frameworks," he said. "But if there's one thing Appcelerator and we as community should learn is that it looks like we have to do a better job at getting the word out. The word that Appcelerator has been doing this for years!"

Well, not quite. The differences between the two approaches are varied and numerous and too extensive and technical to get into here, but obviously React Native is a much more limited offering -- used by many simply for the "view" part of the Model-View-Controller (MVC) architecture -- while the Appcelerator/Titanium ecosystem is much more extensive and complete. Not to mention React Native isn't a cross-platform approach and will be open source -- and thus free and not positioned for use with any other specific software.

In addition to Facebook, mobile dev tool specialist Telerik also recently debuted its own JavaScript approach to native mobile app development: NativeScript.

Now a subsidiary of Progress Software Corp., Telerik introduced NativeScript in a webinar last Friday. "This keynote changes everything we know about mobile app development," said program manager Ruslan Mursalzade in the webinar. Telerik is targeting NativeScript for native development of iOS, Android and Windows (Universal) apps.

The project uses a NativeScript Modules Layer to translate JavaScript calls to native APIs. "The JavaScript call doesn't get compiled, but instead it is interpreted at run time," a company spokesman said in a video. "There is no need for any wrappers to access native APIs, and as a result, there are no limits in terms of which native API functions your app can call. This is the foundation of the NativeScript framework."

And, of course, new projects that exhibit JavaScript's new direction are coming online regularly. For example, building on the React approach, the Reapp project was launched last month, already promising "a new way to build apps with React and JavaScript."

"React Native will be awesome," the Reapp project Web site states. "But you still need lots of work to make an app for all three platforms with it, and you'll need to know Objective-C and Java if you ever go outside of the React Native sandbox."

Reapp and other new approaches to JavaScript development leverage new capabilities in ECMAScript 6, the latest version of a JavaScript standardization effort undertaken by Ecma International, expected to be released midyear. (JavaScript is often referred to as an implementation of ECMAScript, much as ActionScript or Microsoft's JScript.)

"The Sixth Edition adds significant new syntax for writing complex applications, including classes and modules," the Wikipedia entry states. "Other new features include iterators and for/of loops, Python-style generators and generator expressions, arrow functions, binary data, collections (maps, sets and weak maps), and proxies (metaprogramming for virtual objects and wrappers)."

Yes, that's right: The lowly scripting language that was reportedly given its unfortunate name to capitalize on the '90s hype around Java is now getting more Java-like object-oriented programming (OOP) constructs. Already ubiquitous in the development world -- as evidenced by its consistently high rankings in programming language popularity indexes -- it's promising to become even more pervasive in projects everywhere.

It has long since migrated from client-side-only to the server with popular projects such as Node.js and many others. It's also gone from single-page application (SPA) approaches to "isomorphic" models where JavaScript apps can run on the client or server.

It also might even go to the desktop.

"How sane is it to do this for desktop apps?" asked an audience member during a "deep dive" into React Native in the January conference hosted by Facebook.

Right now, presenter Christopher Chedeau said, Facebook is concentrating on iOS and then Android. "But we're trying to think bigger," he said. "But it's a matter of resources." He speculated that maybe "one year down the road" some progress might be made in that area, or suggested volunteers could help spin up a Windows version or something comparable for the desktop.

However, it should be doable, Chedeau indicated, as there's nothing platform-specific in React. "If you can bridge components and APIs, you should be able to do it," he said.

So hang on -- the JavaScript bandwagon is going on an exciting ride!

Where do you see JavaScript going from here? Please share your thoughts in the comments section here or drop me a line.

Posted by David Ramel on March 11, 2015