JavaScript vs. C++? Cascades Lets You Make Native Apps With Both!

Cascades

I’m a web developer. Yes, I did have some C/C++ chops back in the distant past, but jumping in and building a native mobile app today is something that gives me pause. So imagine my surprise when I learned that BlackBerry 10 native apps can be made with JavaScript. Intrigued? Yeah, me too.

I’m still pretty new to RIM, and still learning all the new tools we have to offer. So there I was in Cascades and C++ training when something caught my ear. It went something like this: “Blah blah blah C++ blah blah posix blah blah QML blah blah JavaScript…” Wait! Back up; did you say “JavaScript?!”

Turns out, the native Cascades framework doesn’t just support JavaScript; it’s baked in. The implications hit me fast and my head started racing with ideas. From that moment on, I quietly raced into my own little world of coding and exploring. Here’s what I found:

You can create a fully native BlackBerry 10 UI using QML and JavaScript

QML looks sort of like HTML and JSON had a baby. Check this out:

import bb.cascades 1.0
Page {
       Container {
              Label {
                     id: hello
                     text: "Hello World!"
                     horizontalAlignment: HorizontalAlignment.center
              }
              Button {
                     text: "Welcome!"
                     onTouch: {
                           // this is some JavaScript!
hello.text = "Thank you!";
                     }
              }
       }
}

You can even “subclass” and customize native controls within QML and JavaScript. Even better, the native IDE has a live UI preview and a properties inspector. Both cut the learning curve down to where even a noob native developer like me can get in and do some serious damage in a short time.

You can build many native apps purely in JavaScript

BlackBerry 10’s native Cascades framework exposes its goodness to C++ and JavaScript. It’s like having a browser engine without all the fuss; you’re connected directly to the metal. This means web developers can explore the wilds of native development in BlackBerry 10 without having to stray too far from our comfort zone.

TITLE_IMAGE

You can expose other C++ code to the JavaScript layer

This means that if you run into something that really needs some seriously optimized C++ code to get it running, you can still have the convenience of your application logic being in JavaScript. It’s not an all or nothing scenario. What a great ice breaker to have with native development folks; working on the same project in peace and harmony (flowers, moonbeams and unicorns are optional).

The web is still in there; it’s just in a UI control

Even the most die-hard native developers recognize that some things (like, say, content) are well suited for HTML and such. That’s why most native libraries out there provide a web view of some sort. BlackBerry 10 is no exception. In fact, I’ve met web developers who are using a hybrid approach: writing the UI for their app in QML, application in JavaScript, contents and other goodies inside a web view inside their app; all baked into a single native BlackBerry 10 app. Sounds crazy, but the results are pretty cool.

So why would you want to do this? What about the web… versus native debate?

The deep truth is, native apps will always be more suited to many high performance and demanding applications. While HTML5 gets more awesome every day, sometimes you may have the urge to push beyond what is offered in the browser engine (or ignore it entirely). There’s nothing wrong with having these thoughts, and now that you have a slick outlet for them in BlackBerry 10, there’s no reason not to go exploring.

Ready to get going? Here are some resources to help you on your journey:

The Cascades SDK page: https://developer.blackberry.com/cascades/

Some samples on GitHub, with lots of JavaScript: https://github.com/blackberry/Cascades-Samples

You can ask me more on Twitter too – @balmer

About Dave Balmer

Senior Developer Evangelist for Research In Motion, HTML5 advocate and JavaScript guru.

Join the conversation

Show comments Hide comments
+ -
blog comments powered by Disqus