Books start to catchup to Web 2.0
I have some of the classic JavaScript books like David Flanagan's 2002 JavaScript the Definitive Guide and Danny Goodman's JavaScript Cookbook from 2004. And these books are still good reference and resources for JavaScript coding. But they are before the JavaScript New wave that is AJAX, Web 2.0 and large-scale JavaScript-ed programs everywhere.
It is the latter point that has in effect obsoleted the old JavaScript texts in the sudden drastic change that is IT development today. Your basic skills are okay; but the details are subject to dramatic change in 2-4 years time. Suddenly typical scripts are not 20-30 lines of code but 10 to 20 times that in length as JavaScript embraces OO design, data connections and communications, plus data serialization, validation, and synchronization as basic tasks. So I have been in the market looking for new JavaScript books that can bring developers like myself up to speed in the new Web 2.0 JavaScript.
And these JavaScript books will have to go beyond AJAX, XMLHttpRequest, and E4X. In addition, they will have to emphasize Object Oriented design and Class creation, the relationship between objects, functions, and associative arrays, plus the importance of events, messaging, callbacks in the new world of distributed systems where synchronization is the name of the game. So without further todo - here are two new books from the Pro JavaScript series from Apress.
Pro JavaScript - Design Patterns by Ross Harmes and Dustin Diaz, Apress $45
I have never been too fond of Design Pattern books because they remind of my "favorite" business analyst who was so fond of saying "don't ask me how to code this, its a good design and I don't code - you are the expert in programming, so just go do it". And hence from her ilk was born Extreme Programming where Planning is a Game.
And so the yin-yanging between design and pragmatic coding has plagued software development for the past 40 years. It is a contest between the Systems Analysts who marry the business requirements with the current popular design principles of the day but often without reference to practical coding realities and trade-offs versus the programming cowboys who are anxious to show off their whiz-bang skills but also too often without reference either to the design context or to the business priorities and constraints or both. Good project managers are constantly making sure that business, design and coding feasibilities are clearly on all players minds.
Well in Pro JavaScript Design Patterns I am happy to report that coding and design have come together very well. In fact, Pro JavaScript Design Patterns starts off with a full chapter to review the expressivenes and malleability of the JavaScript language. This is not a complete review of JavaScript, so readers wanting to come up to speed in JavaScript syntax, statements, and predefined functions will have to look elsewhere. But the review of the many different ways that objects and classes can be defined will be a boon to the intermediate to Pro JavaScripter.
Then the book carefully goes through object design principles. First there is a chapter on interfaces and how they provide a viable alternate to inheritance for some desgn situations. The trick here is that interfaces, like namespaces, are not built into JavaScript - so the authors show how to simulate interfaces in JavaScript. That creates another problem that I discuss in the summary below. The next chapter is on encapsulation and information hiding where we encounter similar problems withe lack of a complete JavaScript OO syntax. The last chapter on OO JavaScripting is the one I expected to be first - Inheritance and the issues of polymorphism and overloading. Again, Pro JavaScript Design Patterns shows the ways around these problems with aplomb.
Finally, with the fifth chapter, the book transitions from OO programming techniques to discuss the Singleton Pattern. Pro JavaScript Design Patterns starts off with a barebones JavaScript implementation of the Singleton Patter and then quickly embellishes it in the appropraite contexts. All the 4 chapters of OO in JavaScript development quickly pays off - users can see immediately how the code works and some of its advantages and disadvantages. And that is the second reason I like this book - the authors are not afraid to point out the trade-offs (the plus and minus risks, if you will) of using various OO coding and design methods=patterns. It all falls into place.
Proceed to chapter 8, the Bridge pattern and one gets to se how to use the pattern to implement AJAX code. Specifically, the authors implement a simple but effective messaging queue. because of the first 4 chapter, the OO programming is clear. However, the drawback is th
Proceed 3 more chapters to the Command Patterns which use the JavaScript interface coding hacks proposed by the authors and suddenly a menu bar design makes imminent sense. This is the value of the book - it not only shows the JavaScript code but also shows how the patterns work in pragmatic circumstances. So I go look at the Adobe Spry menubar widget and I discover that ... I leave this as an exercise for the reader.
Now some will argue that this book falls short of the complete set of patterns provided by Gamma et al or in Larman's book on UML and Patterns. True. But this book stays so focussed on showing OO patterns and how they can be coded and used well in JavaScript I don't care. In fact, I can say this is a jewel of book for those Web developers looking for insights into the flood of Web 2.0 JavaScript frameworks, libraries and APIs.
Pro JavaScript Techniques by John Resig, Apress 2008, $45
Pro JavaScript Techniques goes beyond the design and coding that is the emphasis Pro JavaScript Design Patterns. Rather it look at the complete Web 2.0 development process which for many JavaScript programmers will be new and more involved. In Web 2.0 applications users have to be concerned about Client plus Server debugging, database connections and possibly transaction processing, plus the deployment nuances of Web 2.0 applications.
However, Pro JavaScript Techniques has done thinngs in reverse. The chapters on debugging and deployment with an emphasis on creating usable code are in the first 4 chapters. Strange.
Also like Pro JavaScript Design patterns, this book assumes users are fully up to speed in all aspects of JavaScript syntax and semantics. there is only a cursory 1st chapter on OO programming - some users may want to read Pro JavaScript Design patterns first.
With chapter 5 comes the meat of the book. This chapter covers the DOM-Document Object Model and how the underlying XML that is HTML and CSS can be processed
by JavaScripters. A couple of major approaches are explored. But that leads into the next two chapters - Events and JavaScript with CSS. These chapters give users insights on how JavaScript can be used to access, change, and delete both CSS and HTML DOM nodes. As well the key roll of GUI and data events in triggering and controlling those operations are sppelled out. There are details enough
The next two chapters then provide actual usage of the techniques previously learned to populate and validate forms and create an Image Gallery. I like this approach because it applies basic JavaScript OO techniques before getting involved in the coding complexities that are callback functions used with AJAX XMLHttpRequests and other RPC-Remote Procedure Calls.
The next 4 chapters are devoted to JavaScript and AJAX. This intro is a ittle short - it does give 3 examples of AJAX methods; but I had expected more discussion of the different "AJAX"=Remote Access repertoire open to JavaScript developers. however, the author more than makes up for this miscue with the following 3 chapters that discuss using AJAX to enhance blogs (WordPress is the core example), do and create or extend a JavaScript Wiki.
These are just the types of projects that JavaScript coders are likely to hired to do. And the details covered by Pro JavaScript Techniques along with the coding examples available at the website will be for some worth the price of admission.
However, I had two complaints. First, I had bought this book because I knew that John Resig is the developer of the JQuery library of Javascript functions. I was surprised to discover that JQuery is discussed but not comprehensively. The second concern is about the chapter on the Future of JavaScript. Again, John takes us through upcoming JavaScript 1.6 and 1.7 and their feature sets.
But for some strange reason, the author does not discuss what is the timeline and factors impeding or accelerating their adoption. Even more vexing, he does not mention the Rubicon that is JavaScript 2.0. All the missing JavaScript OO syntax on interfaces, inheritance, and namespaces are in JavaScript 2.0 along with a new strong typing requirement and new declaration syntax. But unless JavaScript 2 has some built-in backward compatability, a lot of current JavaScript code is just not going to work. Adobe with ActionScript 3 which is built up from JavaScript 2/ECMAScript 4 base is currently going through this transition - and like VB5 to VB6 before, its not pretty. JavaScripters desrve to be forewarned.
Summary
With these two books one can see how much JavaScript has not so much changed but expanded its role in the past 4-5 years. JavaScripter are no longer in the Kansas of small to medium scale, on-the-client-primarily scripting tasks. The whole ditributed processing Cloud is now a part of javaScript use space. Thats why these two books are important.
One of the things that makes some books stand out is not their contents alone but the supporting websites. Pro JavaScript techniques has code available on the Apress sitewhile Pro JavaScript Design Patterns has its own site. Both sites have code, errata and some good links; but neither is a powerhouse like say Ajax Design Patterns. Nontheless, these book are very approachable with Design Patterns having the learning advantage and Techniques having some very useful code examples.