Learn more Shop now Shop now Shop now Shop now Shop now Shop now Learn More Shop now Learn more Click Here Shop Kindle New Album - Foo Fighters Shop now Shop now

Customer Review

on 7 November 2010
This book gets 5 stars for illustrating Design Patterns within the context of usable examples. It's not as abstract as the Gang of Four book, much more in the realm of a Cookbook of practical examples.
But the book also has its flaws.
* For one thing, duck typing as I understand it from the realms of using Groovy, doesn't mean you have to adhere to an interface, just provide the methods.
Their implementation ties things together via an intermediary interface. To adhere to duck typing, the intermediary interface shouldn't strictly be necessary.
* Their interpretation on how to implement an interface solely relied on the presence of a function/method name. Coming from a Java background originally, seeing a class implementing a method by name alone seems insufficient. The signature of the methods is also crucial. There were no assertions on the types or number of the arguments passed, which I thought an interface should adhere to.
(I realise JavaScript is a dynamic language, so maybe there was grounds for this, but informing the readers why they went with the implementation they did warranted a discussion).

The book also tends to fail in certain areas :
* At times the book would make a suggestion as to something you could do, without showing an example :
** eg lazy loading Observer P223.
** Also, whenever the book forayed off into the realm of Ajax, server-side references were made to PHP scripts that weren't contained in the book (or code download :-( ).
(example Chapter 7 Factory Pattern P107. The section on whitelisting was described. I was rather disillusioned not to see such code within the pages of the book showing how this is done).

* At times the book would show a revised version of some code, without pinpointing the salient changes in the narrative, so you had to really study and compare code.
(eg P248/9 - should have mentioned argument was now being passed in to function)

* Chapter 6 on Chaining. The concept is something I'm familiar with, having used jQuery, but the tail end of the chapter seemed too cryptic for my taste. Too many missing pieces of the puzzle.

* The lack of descriptive argument names for closure functions. Specifically:
** 1) string replace (page 152) - It can take a regular expression and closure as arguments. The closure itself is described with arguments called 'a' and 'b'. This is so unhelpful. If the string replace takes the regular expression/closure arguments, then I believe the arguments should be of the format capture group 1, capture group 2, .... capture group n, position, original text. As there was only one capture group I couldn't get my head around the code with all the cryptic variable names.
** 2) JavaScript 1.6 array functionality (some/filter) : These methods take a function closure that should return a boolean for each element in the array that is being processed : P219/220. As far as I'm aware the inner closure that these methods uses takes 3 arguments, the first is the item of the array, the second the index position. the third the array itself. I'm wondering if you specify a single argument ths just would be the item.... It seems quirky that the third argument is ever needed, since this is the array you are running some/filter upon to begin with...) But the author just uses a name e1. To me this just has no meaning whatsoever. And a return statement without a boolean seems plain wrong in the context of the some/filter closures.
* P237 getContext('2d') - wasn't described. (I've since read about this in Pro HTML5. It's used in conjunction with the canvas tag, for two-dimensional graphics rendering. That book pointed out the fragility of this code. Canvas isn't available in all browsers and the code should be in a try catch block. Internet Explorer is the usual suspect here!).
* P238 I couldn't see why author didn't move undo functionality into UndoDecorator, undo function itself..

* From time to time, the ordering of the code didn't help:
** (Chapter 8: example P110 - ssynchRequest. I suddenly though authors had gone all YUI on me (This is not native JavaScript). Only to find it mentioned for first time on P112. A quick heads up this is about to be covered would have worked wonders)
** (example P171/172. The code at top of P171 should have been shown first. This way by the time you get to see the function, you appreciate why it's been coded is such a way).

* The author seems to flit between naming variables for functions with a lowercase at the start of the book, but by the end has flitted to uppercase. I thought uppercase variable names was supposed to be reserved for classes.
* P132 ev should be e.
* Chapter 8 P112 Why have send with (postData || null). The or null seems redundant. Describe reasoning. (Dustin tells me this is to translate undefined to null - as the send method only likes null or data)
* Chapter 9 P131. Comment about implementation with Cookies not being best approach. Why give an example that is lame? Give me examples that are production ready! This is a 'Pro' series book right?
* Chapter 12 (Decorator) has errors in the code. It's worth looking at the errata on the APress website here. It revolves around the use of 'this' to assign the superclass constructors.
I think all of the Decorators in this chapter suffer from same fate, not just the one described. There seems to be a repeating pattern (pun intended)!

If some of these issues had been addressed, I would have had no hesitation in awarding the book five stars, as it was an engaging and enjoyable read. It wasn't too heavy either, something you can easily read in a weekend.
0Comment| 5 people found this helpful. Was this review helpful to you?YesNoReport abuse| Permalink
What's this?

What are product links?

In the text of your review, you can link directly to any product offered on Amazon.com. To insert a product link, follow these steps:
1. Find the product you want to reference on Amazon.com
2. Copy the web address of the product
3. Click Insert product link
4. Paste the web address in the box
5. Click Select
6. Selecting the item displayed will insert text that looks like this: [[ASIN:014312854XHamlet (The Pelican Shakespeare)]]
7. When your review is displayed on Amazon.com, this text will be transformed into a hyperlink, like this:Hamlet (The Pelican Shakespeare)

You are limited to 10 product links in your review, and your link text may not be longer than 256 characters.

Please write at least one word
You must purchase at least one item from Amazon to post a comment
A problem occurred while submitting your comment. Please try again later.

There was a problem loading the comments at the moment. Please try again later.