Jun 14, 2008 2:22:19 PM

Tags: Javascript

Javascript has been in the news recently in a Zend Framework context. As a developer who's always focused on efficient and secure backend code, I've always had issues with Javascript: it's slow, and you have to deal with maddening inconsistencies across browsers. But as much as I can't stand using it, I can't deny the richness that it can bring to web-based user interfaces. Here, then, are seven reasons why I both love and hate Javascript.

  1. Performance

    I'll never understand how my PC can render visually stunning 3D environments, each frame of which consists of millions of polygons, but my browser falls to pieces when I try to sort a table with two-thousand rows. Let's be honest: Javascript is poorly implemented. This lack of scaleability adds an extra hurdle to the already-painful experience of having to develop reach frontend interfaces that make user experiences better, not slower.

    But one can't condemn a language because of the way its interpreters are implemented. I acknowledge that Javascript is a powerful client-side language that is a feature of Web 2.0. I'm certain, as modern browsers continue to mature, and as Web 2.0 becomes Web 3.0 and 4.0 and so on, that Javascript implementations will continue to improve, to the point that it's as integral in a web application as backend scripted languages.

  2. Configurability

    Javascript generally has no configuration. In Firefox, for instance, there are only six or seven items in about:config that refer to Javascript, few of which have anything to do with fine-tuning or performance. The result is that Javascript comes voetstoots, and performs as it was coded to perform by the browser's developers.

    An interesting result of this, though, is that Javascript performance and behaviour is relatively consistent across homogeneous browsers. Consider, for instance, the headaches you may have experienced with PHP's magic quoting (soon to be deprecated). In PHP, you have to take server configurations into account, and consider each option that may be set differently on a client's server. With Javascript, however, that confusion is mitigated.

  3. Syntactic Freedom

    Javascript offers an incredibly rich syntax, from { object: 'literals' } to [ JSON ] and /^regular\ expressions$/. These syntactic elements allow for lean and readable code. It sometimes astounds me how much can be achieved with Javascript in so few lines of code, particularly when you bring powerful CSS selectors into the mix, such as :has() and :gt() offered by Jquery.

    As any coder will know, though, the more powerful a syntax, the more often it can misused. Debugging Javascript code can often be tricky because there are so many ways to achieve the same outcome. Coding standards exist for Javascript, but they are rarely used. Instead, Javascript code is often a mish-mash of braces, slashes and square brackets that is difficult to sift through.

  4. Poor Debugging

    Apart from Javascript being poorly implemented from a performance point of view, JS debugging is nearly impossible without third-party extensions. Error messages are vague, ambiguous and non-specific at best. The status quo has improved over recent years, evolving from the IE yellow triangle of death into Firefox's error console, but these tools still don't compare to the kind of error reporting that coders expect from backend scripting languages like PHP. True -- Javascript has a good exception handling mechanism -- but it isn't used nearly as often as it should be.

    There is a selection of tools available to compensate for this weakness, however. And despite the fact that these tools often require specific code injections, such as Firebug's console.log(), they make the task of debugging Javascript a little less laborious.

  5. Mobile Implementations

    In Africa, mobile penetration exceeds web penetration by some way. But there are few mobile implementations of Javascript, and even those mobile browsers that do support Javascript offer only buggy versions of their desktop counterparts. I include Safari on iPhone and iTouch in that list, together with Opera Mini.

    The discrepancy between desktop and mobile, though, forces developers to build websites that degrade gracefully on mobile. And that is a good thing. As a developer in South Africa, the budget is often not available for separate development of WAP websites, so it's important that websites render properly on mobile devices. This forces me, and other developers in South Africa to build websites semantically first.

  6. JSON and XML Support

    Javascript offers support for both XML and JSON, allowing it to communicate nicely with backend server technologies. This interaction has precipitated Web 2.0-style frontend web interfaces, allowing the browser to make requests and receive feedback from the server without the page reloading.

    But, in my opinion, Javascript's performance still hinders scaleable XML solutions. Although JS handles XML well from a syntactic point of view, as the number of nodes in an XML message increases, its performance starts to drop dramatically.

  7. Frameworks

    There are several Javascript frameworks out there that help to abstract away browser differences, both in terms of DOM handling and in terms of CSS. Jquery, for instance, offers a CSS selector tool which compensates for browsers that don't support particular CSS selectors. ExtJS takes this a step further by offering a widget API.

    The problem that I have with current JS frameworks is that they focus far too much on what functionality they offer, and far too little on creating consistent Javascript methodology for using OOP. Jquery offers only a set of functions for creating procedural applications. The OO part is left up to the programmer. ExJS encourages inheritance of its own classes, but these classes are in no way reusable with other frameworks. The result is that picking a JS framework is an all-or-nothing decision, something which is strongly contrasted by PHP frameworks which allow mixing and matching.

I really hope that Javascript implementations continue to improve, because the web community will benefit from richer user interfaces which scale and behave consistently. Until that happens, Javascript will always be an afterthought.

Recent Posts

Discussion

Subscribe to an RSS feed of these comments

maxime

Jun 17, 2008 6:53:44 AM

Hi,
Great article, completely agree with you.
Do you know Mootools ? It's a great framework with a very good OO implementation.

Neil Garb

Jun 17, 2008 7:05:32 AM

Thanks for your comments, Maxime. I'm not saying that particular frameworks don't have great OOP structures. I really like ExJS -- reminds me of my MFC days.

I'm just saying that there is no standard. Prototype, for instance, uses Class.create(). Jquery has a plugin architecture. I haven't looked at Mootools in any detail, but the point is there's no standard for OOP interoperability.

Piotr Zalewa

Jun 17, 2008 10:59:37 AM

According the Mobile implementation ... I think that the solution to this is to always use the unobtrusive javascript. All functionality should be coded first with the non javascript way and on the beginning javascript should test what's possible on that particular device. As you said - degrade. I understand that it is a pain, but I think the best option would be to use the downgraded mobile javascript as an essential tool and add only additional tweaks with the javascript it does not allow.

Neil Garb

Jun 17, 2008 5:39:52 PM

@Piotr: absolutely. Gracefully degrading websites should be the norm. It's interesting that the fact that Javascript implementations *are* poor forces you to build websites correctly.

Piotr Zalewa

Jun 28, 2008 9:01:16 AM

I was just curious (as I haven't yet done in that way) is there any method to change the behaviour of the javascript app depending on the javascript implementation? I.e. Nokia phones - they have some sort of javascript inside, but the Ajax is simply not working. It's not enough then to just degrade to non javascript.

Neil Garb

Jun 28, 2008 10:13:24 AM

@Piotr: tricky. My first thought is that execptions would work nicely for this:

try {
// something that doesn't work
}
catch (...) {
// degrade
}

That should work in most instances, but won't cover you if the function calls/syntax inside try {} are not implemented. If I'm not mistaken, the JS interpreter will bail.

John Smith

Dec 9, 2009 3:05:31 PM

Javascript is a filthy spy tool designed by Jews to remotely manipulte the registry of peoples computers.

The wise surf the web with javascript switched off.

The other 99.9% ignorant point and clickers surf the web with it
switched on and then wonder why periodic reinstallation of Windows is required

Chris

Jan 22, 2010 8:12:35 PM

I hate Javascript and web applications PERIOD.

Use Silverlight for lightweight slick looking lightweight business apps... and use XBAP (WPF) for business class internal systems.

Too many headaches with browser compatibilities and other ridiculous crap to deal with...... I found this post because I am stuck at work while one of my developers is fixing a bug in the UI because of a Javascript latency timing issue.... it's Friday... and the build is 2 hours late and I'm not happy. =)


C

Your comment