Sign In/My Account | View Cart  
advertisement

Article:
 RSS and AJAX: A Simple News Reader
Subject: Poor JavaScript quality
Date: 2006-09-14 02:36:03
From: Asbjørn Ulsberg

The JavaScript quality wasn't the best I've seen. Not the HTML either, but since that isn't really the topic, I'll resist the urge to comment upon it any further. But the JavaScript doesn't do much error recovery, doesn't declare all variables, doesn't check object existance prior to their usage and does some really ugly and nasty HTML concatenation with innerHTML.


Plus, everything is just loose functions without any protection from other JavaScripts one might want to use on the same page. Instead, all of the functions should be kept inside a wrapper function or object to avoid conflicts with other scripts.


I would advice the author to, instead of trying to invent his own set of wheels in this area, use existing libraries for basic stuff like this. Both Yahoo's Ajax library and Prototype are excellent and hides all this mess from the author and on top of that does all of this much neater and better than most others (including me. And the author of this article).


Previous Message Previous Message   Next Message Next Message


Titles Only Titles Only Newest First
  • Poor JavaScript quality
    2006-09-15 07:31:43 sobes


    First off, thanks very much for your feedback on my article. This is the first time I've written for XML.com, so all responses are much appreciated.


    The JavaScript quality wasn't the best I've seen. Not the HTML either, but since that isn't really the topic, I'll resist the urge to comment upon it any further. But the JavaScript doesn't do much error recovery, doesn't declare all variables, doesn't check object existance prior to their usage and does some really ugly and nasty HTML concatenation with innerHTML.


    I tried to keep the JavaScript as simple and short as possible, while conveying the main point of the article - how to translate an RSS feed received through AJAX into a series of simple JavaScript objects. Although I didn't declare all the variables, I deliberately listed all object properties (variables) at the top of the object constructors so that custom declarations for them can be added easily by someone who'd wish to extend the code. Object detection is used when necessary (eg: "if (catElement == null)..." in the RSS2Category constructor).


    I acknowledge that using DOM functions to create the HTML elements would be a more scalable way of displaying the RSS on the webpage. I used innerHTML for two reasons: (1) cross-browser compatibility and (2) simplicity. As mentioned, showRSS(RSS) is not meant to be the focus of the article. Using DOM functions would mean having a much larger showRSS(RSS) function, and there'd be a few browser workarounds that I would've had to explain.


    Plus, everything is just loose functions without any protection from other JavaScripts one might want to use on the same page. Instead, all of the
    functions should be kept inside a wrapper function or object to avoid conflicts with other scripts.


    This is a good suggestion and an example of how the code could be extended to work within a larger JavaScript application. The code for the project is included as a separate ".js" library file precisely to make this relatively simple to do.


    I would advice the author to, instead of trying to invent his own set of wheels in this area, use existing libraries for basic stuff like this. Both Yahoo's Ajax library and Prototype are excellent and hides all this mess from the author and on top of that does all of this much neater and better than most others (including me. And the author of this article).


    Before even planning out this article, I had done research on AJAX libraries, as well as other examples of RSS parsers or readers that have been implemented through AJAX. Despite my research, I was unable to find anything that clearly and comprehensively explains the process of implementing an RSS reader with AJAX in a simple way. Although both of the sources you suggest are excellent examples of AJAX libraries, neither of them actually implement a reader for RSS 2.0. As the AJAX that is used in the article is quite simple (it's pretty much encased in the getRSS() function), I chose not to use an AJAX library.


    Again, thank you for your feedback, and I hope that you've found my response helpful.

    Paul Sobocinski. (author)



  • Poor JavaScript quality
    2006-09-14 23:01:33 allanc@chickenandporn.com

    I think the author's intention was to show a bit of AJAX and show how the XML nature of the AJAX allows the existing tools (browser, javascript) to do much of the work for us.


    The additional error-checking and protection you discuss might have obfuscated the code, perhaps it would have made a nice appendix or next-page to show the reader what kind of protections are needed.


    Leveraging existing tools incurs dependency -- for example, anyone who has said that perl is the easiest hasn't worked through a DLL-Hell to try to get back the 2-yr-old environment that made a stack of perl work. For this same reason, re-inventing a while is more work to the benefit of having no dependencies. I agree that this is a case where the dependencies add value.


    Maybe that is an example that you're very suited to add to this forum. Engineers talk in terms of words, patches, and code. Care to show some code? It might help to show your point, and further assist readers of the original article.


    If my words sound argumentative, it's not intended; I want to applaud the author for putting forth this work for others' benefit and to the scrutiny of the more experienced readers. Very generous!


    Allan Clark
    I make linux handsets; my AJAX sucks


Sponsored By: