Review of “Core Animation for Mac OS X and the iPhone”

After finishing Aaron Hillegass’ Cocoa book during my “Cocoa Crunch” I hungered for some material that dug into specific frameworks more extensively. Notably, the Core Animation frameworks seemed to be essential knowledge these days for both iPhone development reasons and desktop OS X applications. When objects are manipulated by the user, she wants visual feedback about what will happen when the mouse-button is released, for example. Apple products always feature smooth transitions between states, the genie effect when minimizing a window on the desktop, the ripple effect when adding a new widget to Dashboard, the way menu items “make room” for a new object that will be dropped into a list, and so forth.

Of course, 3rd party developers have embraced these techniques over the past few years and the Macintosh shareware community has been able to raise the overall quality of the user experience as a result. The market now is more competitive from a “slick user experience” perspective than I ever recall seeing in the past. I knew I needed at least a little of this knowledge to provide a first class user experience for file_wrangler_2.

The Pragmatic Programmers website has a nicely designed online store for purchasing watermarked (with the purchaser’s name and time of purchase) downloading PDFs purporting to help one learn a variety of Macintosh technologies. Core Animation for Mac OS X and the iPhone by Bill Dudney is my first experience with one of their books, and I have to admit I feel let down.

Overall, I feel it covers the basic ground one would hope to see in such a book. It starts with a look at how Core Animation can be used at its most basic level, working on NSViews and gradually progresses into “full blown” Core Animation, using CALayer instead of NSView, then showing the different types of CALayer subclasses one can use.

We need an editor, stat! (Or to put it another way, what we need at this moment is a person who knows the skill of editing!)

My largest complaint with the book is that is needs editing, post-haste. Bill Dudney’s writing style is incredibly redundant, inefficient, somewhat poorly organized, and spins off into non-important issues. How many times were we “warned” about overusing animation effects in our applications? No offense to the author, but policing our use of Apple technologies is not his job. Is he so afraid he’s opening some Pandora’s Box upon the development world that somehow he will personally be held responsible when everyone’s interfaces start wiggling and jiggling for no reason? By page 39 of this 190 page book I had encountered such “warnings” enough times that I made a note to myself in the PDF margin, “Enough already!” Page 115, section 8.8, has a grievously redundant paragraph about the actionForKey: method.

Too hard for a beginner, too easy for a non-beginner

Dudney spends an inordinate amount of time explaining very basic concepts. Take the explanation of the Ease In / Ease Out curves, for example. Four pages of the book to show graphs that provide only a cursory amount of data and text descriptions that are redundant. If you tell me about “Ease In” and then tell me “Ease Out” has the opposite visual effect, I don’t ALSO need a full paragraph explaining what Ease Out looks like along with a bland graph. Why did the Ease In / Ease Out effects get so much explanation but other transitions did not? Contrast that with the OpenGL section and perhaps you can tell me who the intended audience of this book is?

In some ways he seems to target the beginner, yet I would argue that the book is not really for Cocoa beginners. He doesn’t explain code in anywhere near the level of detail the Hillegass book does, but he also writes as though he’s holding the developer’s hand a lot. He spares us from writing the code ourselves, as the book only contains a portion of the working code for any example (we really HAVE to download the pre-built examples to see what he’s talking about), but I’m not sure that is conducive to learning the frameworks very well. And that may be my biggest disappointment of the book. It seems too difficult for a beginner, as it assumes (rightly) an understanding of Objective-C, the Cocoa frameworks, AppKit, and so forth. Yet it also feels overly simplified for anyone with intermediate experience.

if (nil == [cocoa.accepted.formatting setFormat:dotVersus([self.format brackets])…

The examples in the book need a lot more polish and professionalism applied. The code is kind of haphazard and I found myself jumping up and down through a file to find a called method. When reading code this simple there tends to be a logical progression from method #1 to #2 to #3, yet the book’s code order does not reflect this logic. The code often contains unused ivars and methods. The code for rebuilding the Front Row menuing system has an ivar reference to a CIFilter for the bloom effect that isn’t used anywhere in the program. Yet I did see this filter being used in Apple’s sample code for building a similar menuing system, which strikes me as an odd coincidence.

The author also jumps around in his use (in my opinion, overuse) of dot notation and bracket notation, making the code kind of difficult to follow. @property and @synthesize make rare appearances and seems to only be injected when the author felt like it. No attempts at memory management seem to have been made. Odd use of syntax like “if (nil == someVariable)…” which is correct, but also reads kind of backwards to anything I’ve ever seen written by any other programmer ever. Basically, it just doesn’t feel like good Cocoa programming practices with any real forethought put into the examples. For that matter, the code in the Layer Scrolling and Geometry section doesn’t work right. Whether by Apple’s updates or not, the code has not been updated since June 2009 to provide a working solution to the problems there. I will post my own solution in the Codeshare later.

Oftentimes I would rewrite the code entirely, reorganizing and standardizing on one style, fixing the indents and removing the unusual end-of-line comments (tags for the publisher?). Suddenly the code’s intent was much clearer and easier to grok. I would have to recommend this course of action for anyone working through the book.

Suppressing the imagination

The examples themselves are kind of boring and seem slapped together. Take, for example, the Keyframe Movement example. A “heart” shape made of straight lines is placed awkwardly in the lower-left-ish corner of the window and a poorly lit graphic of a statue moves along the path. Some images float from right to left on the screen. The genie effect is half-heartedly implemented. Some drop shadows are applied to controls (although I did get a kick of of the pointillism effect on them). It did not exactly fire up my creativity, despite what he says on page 15, “Instead of trying to be your imagination, I attempt to spark your imagination. Often examples are contrived specifically to illustrate how something works or fits together rather than because they are a good fit for any particular application. I often choose the less-used effects or items to illustrate a point to try to spark your imagination…” (you may note the redundant use of the phrase “spark your imagination” in just this small excerpt). However, I can recall perhaps a single “less-used” effect in the entire book.

Should we feel “sparked” or “suppressed” when he claims, “We need to spend some time with this new framework building stuff that is gaudy and crazy to push the limits of what is possible.” then twenty pages later says, “Of course, we have to temper our imaginations by making sure that the animation is useful and not just eye candy.”

I can’t say I didn’t learn anything

I am impressed by Core Animation, but I can’t attribute that to this book. Yes, there were one or two examples that raised an eyebrow once or twice. Yes, I was surprised by how easy certain things can be animated. But that is really just a testament to Apple’s work on Core Animation, not because the author was particularly adept at making something complicated look easy. Basically he just made something that is already easy look easy, and I’m not entirely convinced that was worth the $22. I wanted to love this book, but I cannot recommend it over Apple’s free documentation and the plethora of free tutorials on the web.

How it can be fixed

  • edit the hell out of it
  • develop a few interesting projects that we develop over the course of a few chapters
  • pick a target audience and really cater to it
  • build on the teachings of Aaron’s book, adopting the code formatting and best-practices he teaches

Leave a Reply

Your email address will not be published. Required fields are marked *