Titanium App: My Personal Highlight from JSConf2009

Guest post by Greg Ferrell (@gregferrell)

A couple weekends ago (April 24-25, 2009), I had the great fortune to attend JSConf2009, "The First Conference Just for JavaScript Developers". Chris Williams and his wife Laura, spent much of 2008 and the beginning of 2009 putting together one heck of a conference. I have been to a few conferences that were all middle management or salesmen trying to sell a product but JSConf2009 was refreshingly different. Most presenters were actual project developers or experts on the techniques they were showing.

One of the more exciting presentations for me was Titanium by Jeff Haynie of Appcelerator. For those unfamiliar with Titanium, it is an open-source, cross-platform, desktop application SDK that is built on Webkit. Applications are written in HTML/CSS/JavaScript and supports lots of HTML5 goodies. (It also supports writing in Python and Ruby, with plans to add more languages in the future.). If that sounds a lot like Adobe AIR, that's because it is. However, there are some fundamental differences that make Titanium a viable choice and very desirable over other solutions.

To give you a quick overview on my background with this: I write a lot of (unpublished) AIR apps for both my work and home projects because I am one of its ideal customers:

  • I use Macs, PCs, and sometimes Linux, all in the same day, almost every day
  • I need to write cross platform desktop applications, but I only
    know web development related programming languages
  • I need my applications to have full filesystem access as well as
    web access so I can automate repetitive work

When I first heard of Titanium, my initial thought was: "Pfft, I can already do that with AIR and have been since I started using the beta a year or so ago." AIR serves my needs well and so I let Titanium slip from my mind.

However, Jeff's presentation at JSConf2009 very quickly awakened my curiosity about Titanium. His first demonstration was a modified version of pro-web-dev and blogger Jonathan Snook's demo on imitating Tweetie in Titanium. Titanium, being built on a recent version of Webkit, was able to make use of CSS3 transitions that very closely copied Core Animation techniques from OS X. The end result was simply astonishing. The Titanium mimic of Tweetie was so close visually to the original that, with a little work, it could be a 99% clone.

The best part for me was when Jeff showed the Titanium Developer Application (TDA). The TDA, itself being built in Titanium, was a testament to the power of the platform. With the TDA, you can start a new application by entering in your name, the app name, a description, publishing information, app location on your HDD, and a custom app icon. You can also elect to choose popular JavaScript libraries to be included in your app before you create it. More options like window size, max/minimize ability, etc. are available in the app descriptor XML, which is very similar to the AIR app descriptor. Once you declare all of your options for your new application, you are taken back to the projects window where you have options to delete, create more, or go to the packaging stage. There, you can launch and test your app in one click, package with another click, or do a mock installation. The packaged files also have options to include the runtime for tandem installation or, for machines that have RTE installed, just the app by itself.

This was the point upon which I was fully sold on Titanium being a solid platform. Testing, packaging, and mock installing from a single first party dev app should be mandatory. My biggest complaint with developing AIR apps with HTML/CSS/JavaScript is the messy command line process required to test and package the apps. I made my own shortcut to launching AIR apps without the command line because I was so irritated with it. (It's worth mentioning that Aptana can launch and package AIR apps with a simple GUI, but with big kudos to Aptana, it shouldn't take a third party app to make first party development easy. Flash and Flex, however, can run and package from within their respective IDEs.)

There is also a sandbox portion of the Titanium Developer Application that allows you to try small scripts without making a whole new app. This is a boon for me because I frequently make copies of my AIR apps just to test a few small scripts or run a very simple batch job. A sandbox would make that a heck of a lot easier. The TDA does this, and takes it up a notch by letting you include common JavaScript libraries in your sandbox. It also gives you a list of pre-made snippets to see how it works.

The Titanium Developer Application is also a great community tool because it includes: a tab with links for popular apps built in Titanium, a tab with a built-in connection to the #titanium_app IRC chat room, and a tab for Twitter and FriendFeed posts that mention Titanium. Keep in mind that the Titanium Developer Application was itself written in Titanium, so all of these things should be possible in your own Titanium apps.

Jeff also mentioned that, in order for AIR JavaScript apps to leverage Flash classes, it must always have an instance of Flash running in the background within the app. While this offers a great deal of flexibility for leveraging powerful Flash libraries and built in classes, it also causes a severe performance hit. Titanium runs ONLY on an instance of Webkit and therefore has a large resource advantage over AIR. In tests of JavaScript applications that were ported from AIR to Titanium, most saw significant reductions in needed resources to run. For applications like Twitter interfaces or other stay-on web-connected apps, this is a HUGE advantage. Even the best computer can be faster if 10% of its CPU isn't needlessly taken up at all times by a minor app.

Titanium comes with the expected file system access, drag and drop, web connection, and SQLite db access APIs, but throws a trump card on the table with its ability to open processes and applications from the users computer. Jeff quickly went over the ability to use the process API to do something as simple as read the contents of a directory via the command line. I have desperately wanted this ability in AIR because using function recursion to iterate over an entire folder full of files with the File API is MANY, MANY times slower than what the native file system can do via command line.

I have considered communicating with Bonjour via AIR so I could write iPhone apps and AIR apps that could communicate. Titanium's process API may just accomplish this and open the door for easily created, cross-platform apps that can communicate with their iPhone counter parts. Couple that with PhoneGap and you could then have the ability to make iPhone apps and desktop apps for the Big Three OSs that can theoretically talk to each other, all written in JavaScript.

While system process access may seem like a security risk, keep in mind that anything with the ability to write text files to the file system could potentially make a nasty text-based runtime file named "RUN_ME_FOR_FREE_INTERNETS" and screw the system up as well. The key thing here is that you must exercise caution with any app you download, and the presence of system process access to Titanium is no greater a security risk than downloading any random application written in other languages.

As of this writing, Titanium is only in Preview Release 3 and still has ground to cover before it's a complete platform. I think more options need to be added to the existing APIs, like the ability to pass parameters to opening applications, and perhaps some additional APIs to match the filesystem set already within AIR. The documentation could also benefit from some visual improvement. I would love to see a revised version of the docs presented just like jQuery's API browser and be another tab in the Titanium Developer Application. That would be beyond amazing. It would also be nice to have the ability in Titanium (or AIR) to package a standalone app into a "no need to install" executable file, similar to what Shu-Player does for AIR. Aside from those minor quips, Titanium is off to a smashing start and I must thank Jeff for doing a bang-up job with his presentation. I might not have taken a second look at Titanium until much later and may have missed out on a great platform for many months.

I can't possibly go over all of the awesome things Jeff talked about, but if you want to learn more about Titanium app, take a look at the slides from his JSConf2009 presentation, check out the Tweetie Imitation Demo, or go to the Titanium website, grab the Titanium Developer Application, and try something in the sandbox yourself.

Companies like Appcelerator are making it a great time to be JavaScript developer and JSConf2009 really opened my eyes to the inspiring things going on with the JavaScript community.

Lastly, the point of this article is not to talk negatively about AIR, but rather to show the strong points of Titanium in comparison, as Jeff presented it. I still think AIR is a great platform and has lots of advantages in its corner as well.

Editors note: this post was delay by my very silly travel schedule. It's still a great read though!