These days have been quite busy on refining JavaScript architecture for the stats module, and, in the meantime, in drawing a design that could be useful for the overall Melange project's JavaScript layer.
First of all, I've watched an interesting Best Practise in Javascript Library Design video linked by a John Resig's blog post, then I've spent some time on studying or improving my knowledge about best JavaScript practises like:
- Error handling
- Closures
- Common patterns (and more infos about Module, Decorator and durable objects)
- Some articles about Javascript tips, how to write efficient Javascript, and antipatterns like global namespace pollution, misuse of for..in and with statement.
- jsLint, testing it against some of my example code
I've integrated a slightly modified source code of the jsLint rhino version, to be compliant with the following options of the online version.
- JSDocToolkit: it's been a little bit difficult to explain in JSDoc syntax the architecture, but finally I came up with something sensible :)
- JSUnit, for Javascript unit testing. I've also put some example unit tests in the repository.
- JSCoverage, and this is, to me, the most exciting tool to work together with JSUnit. Changing JSUnit's source code a bit as explained in their FAQs, and using a proper script to instrument our JS source code, after you've run unit tests, you are shown a page like the following one, that shows how much of the source code has been covered by the tests
Clicking on the name of the Javascript file, you can know which lines are actually covered by the tests and how many times they have been called
- Shrinksafe, to minify our Javascript code before releasing. I've also put some effort on using, for example, JSMin and Packer, and I've found the latter being the most efficient, also trying packing some example code using this wonderful online compressor rater
However, Packer produces a really unreadable code, acting also as a sort of obfuscator, something that probably we don't want to have. Furthermore, Shrinksafe doesn't delete new lines (which can be harmful if we forget to add a semicolon at the end of a line of code), is a little bit more "conservative" and behaves pretty good as well
After committed all these stuff, from Tuesday to Thursday I've attended the wonderful iQ Boot Camp 2009 event here in Dublin. I will never have enough words to describe how thankful I am to iQ Content for giving me the opportunity to attend it.
On Friday I've met with James Crook: we had a great afternoon together, and talked a lot about Melange and a rough architecture for the Python side to support what will be useful to accomplish Javascript frontend tasks.
On Saturday and Sunday I've committed some code to start the melange.graph.chart package (improving tests and adding jLinq code to the repository, too), which will behave as a layer to play with Google Visualization API (also starting to write code to integrate the new Google Ajax API, and, in particular, its dynamic loading, something we will need to integrate according also to Melange issue 634).
To do that, I've used some OOP inheritance, studying some articles (1,2,3). I've also found an interesting jQuery inheritance plugin, but I decided not to go with it for the moment, as it seems to me a sort of constraint more than an opportunity. I will test it later (perhaps this week), and eventually I'll change my mind :)
Furthermore, I've found an interesting site, AjaxPatterns, in which I've found informations about JSON Frameworks and Browser Side Templating, which will be really a must-have for us. I've not yet explored them into depth, but I'll decide with the community which one between JsonML, Ajax Pages, Pure and Two Birds will fit our needs better.
Last but not least, I've updated JavascriptRefactoring and JavaScriptStyleGuide Melange wiki pages according to what I've found throughout these 10 days.
No comments:
Post a Comment