Why the JavaScript obsession?

If you’ve read anything on the web about technology recently you’ll know that many technology pundits and enthusiasts are claiming that HTML 5 and JavaScript are the future of computing. Even Microsoft is jumping on the bandwagon with Windows 8. But is it? Yes it has the benefits of being open, easy to learn and cross platform – but is it the best tool for developers? I’m not so sure, and I think JavaScript is the weak link. There is no compiler to warn you you’re doing stupid things, no way to enforce variables to be declared final or even to be of a particular data type. The extremely loose nature is a benefit when trying to learn it, but when you’re working on a project with thousand’s of lines of code it can get tricky. Want to rename a variable? I’ve yet to see an IDE that can refactor JavaScript the way Eclipse or Visual Studio can with Java and C# respectively.

Maybe I am showing my ignorance here, but it seems to me that JavaScript might be great for small scale projects, but would I choose it for a large enterprise system over Java or C#? Is it popular simply because it happens to be the only scripting language almost guaranteed to be available on any device, rather than because it lets developers write elegant, maintainable and scalable code?

Appcelerator is a tool I’ve been using recently to develop an iPhone app. It’s actually quite good, if not a little buggy here and there – but their central premise is that you can reuse your web skills and code JavaScript instead of Objective C. However, all you borrow from the web is the syntax of JavaScript, since there’s no DOM, no JQuery and instead a bunch of custom components. It’s a nice tool, and will surly get better over time, but I do sometimes wonder why they chose JavaScript as opposed to Java as their supported language.

This reminds me of when “RAD” was big in the mid-nineties, Visual Basic was the future (remember, in VB there was the variant data type that could be anything). A few years later Java was the future, with its strict enforcement of OO practises. Now it’s swung the other way with JavaScript and Ruby be touted as the way forward. What will be next I wonder?

PhoneGap: The JavaScript files are different!

I have recently been developing with PhoneGap, the cross platform development kit for mobile devices (essentially a browser window that lets you run HTML 5 web sites as an App)

I started off developing for iPhone and Android, using the packages provided by their download to get up and running. Great stuff. You write an app using HTML 5, JavaScript and CSS3 and then deploy to each device. The PhoneGap package contains a directory for each platform, with a number of files – the important one being phonegap.0.9.4.js.

So I developed the app on my Windows PC, copying the files across to my trusty Mac to deploy to iPhone. There are some subtle differences in the way Safari and Chrome render, so it was important to test across both devices. I kept coming across intermittent problems on the iPhone however, with the deviceready event not firing. What was going on?


Due to the negligible amount of documentation available on PhoneGap’s site (Hey – I am used to having MSDN at my disposal!) I found myself digging through the sourcecode to work out how on earth I could do things. I noticed a lot of Android specific code, but no iPhone code. How odd. I then checked in my BlackBerry project folder and noticed the file was much bigger.

Yes, folks – the various phonegap.0.9.4.js files – despite having the same filename are totally different for each OS implementation. Not once in the many hours spent reading PhoneGap’s web site did I see anything that told me that. Turned out my iPhone problems were because I was deploying an Android version of PhoneGap to the iPhone. Having the same filename is confusing and they seem destined to get used in place of one and other. I suspect many others will have tried to deploy the wrong file to the wrong device.

I would really like to see the folks at PhoneGap have a more sensible naming convention. e.g.  phonegap_android.0.9.4.js? It would be apparent straight away the it was specific to that OS, and avoid what amounts to DLL hell issues for mobile apps.

Of course a file is a file, and I can rename it to whatever I like (and probably will) – but it’s nice not to have to (who renames jQuery?) and would certainly make learning the platform easier.