mercredi 22 avril 2009

Object Oriented JavaScript




Web 2.0 heavily relies on JavaScript. After being forgotten for a while, there is a tremendous interest in JavaScript and other web technologies. Real applications are now convoluted, which forces developers to follow a strict and disciplined programming style.

``Object Oriented JavaScript’’ nicely relates the large experience of Stoyan Stefanov in web programming. His book covers object-orientation in JavaScript and gives valuable information for both beginner and experienced practitioners. No prerequisite skill in both of these fields is assumed.

The first chapter helps the reader to set up a proper programming environment using Firefox and Firebug. This will help the reader to exercise along the reading. A brief introduction object-orientation is provided.

The second chapter enumerates important language constructs. This chapter is a bit unappetizing since it simply list syntactic constructions, without having a story to tell. Beginners will probably gain a quick grasp on the essential constructs (variable definition, loops, condition). Experienced programmers will not do more than quickly skimming.

Chapter 3 is much more interesting by reviewing different kinds of functions supported by JavaScript. Beginners will learn how to define and apply functions. Experienced readers will enjoy expressiveness of high-order functions (although this terms is not mentioned), self-modifying functions, and closures.

Chapter 4 is about objects. It shows the different ways to create objects and what are their associated operators. It also describes built-in objects, including RegExp, a linguistic construct to define regular expressions. Reader will probably miss the table of special characters that may be used in regular expressions.

Chapter 5 describes JavaScript’s prototype-based object model. It goes into deep details. However, the lack of motivating and useful examples has great potential for leaving JavaScript learners disoriented. It is like handing powerful tools to someone without explaining what they are good for. At the end of the chapter, it is still unclear when one should use ‘prototype’ instead of ‘__proto__’ or constructor’s prototype.

Chapter 6 deals about inheritance and brings to the light some uncertainties left by the precedent chapter. It reviews different ways to create and simulate inheritance, some having a heavy hackish flavor.
A wrong definition of what mixins are is unfortunately given. The first concrete example of the book comes at the end of this chapter. Readers will enjoy the JavaScript version of the ubiquitous geometrical shape example.

Chapter 7 is about the browser environment. It summarizes in 55 pages how your JavaScript program may retrieve information from a web browser, webpages, how it may attach an event to any piece of html code, and updates a subpart of html pages. This is at the very root of AJAX’ success.

The last chapter provides a nice set of JavaScript specific design patterns and good programming practices. One of these patterns is troubling. The Init-Time Branching pattern promotes the use of conditional statement to discriminate the version of the user web browser. A double dispatch would be more convenient.

Each chapter proposes few exercises and ends with a summary. References for further reading are provided time to time. More would have been welcome. The book uses a compilation of independent small do-it expressions and foobar examples. No construction of a useful application is presented. This is sad since readers will be left to themselves looking for a practical application. The few pictures are not always clear (e.g., Page 182).

This book is free from a serious Software Engineering consideration. This is a bit troubling since the book aims at focusing on creating scalable, reusable high-quality applications and libraries. No much is said regarding how the development phase of a multi-developpers project must be conducted, as well how to gain scalability and identity bottlenecks in web applications.

All that said, even if it will probably be complemented by other sources, I recommend ``Object-Oriented JavaScript’’ to people looking for a broad and deep presentation of JavaScript.

Aucun commentaire:

Enregistrer un commentaire