mardi 2 juillet 2013

Effective JavaScript : 68 specific ways to harness the power of JavaScript



The JavaScript wave began in 1995, and has largely become established as the new standard for creating lightweight client applications. JavaScript has a not-so-flattering reputation among programming language experts because it contains many odd features. Consider the (in)famous command, “3 + true,” which surprisingly returns 4. JavaScript was rapidly conceived (in about 10 days, according the preface of this book) and has been rapidly adopted, meaning that odd and suboptimal aspects of the language are likely to stay with us for a long time. So we have to deal with them, and this book is about exactly that: how we cope with the mysterious aspects of JavaScript.

The author aims to uncover many of the details and oddities an experienced JavaScript programmer might easily stumble on. The book reviews 68 items of the language that are considered error prone (for example, “Item 32: Never modify __proto__”) or counter-intuitive (for example, “Item 3: Beware of implicit coercion”).

The book concisely details obscure aspects of JavaScript. For example, it describes how to operate the lookup function over the parent and prototype links (Item 30). The book makes intensive use of short and independent examples, which are easily reproducible with a text editor and a web browser. The book is well written, with a pleasant writing style and format. Having the content broken down into items makes it easy to browse and search for particular solutions.

By focusing on singular aspects of JavaScript, the book often seems more intent on solving a technical challenge in JavaScript than on addressing practical software engineering issues. Several items gave me this feeling, including items 23, 24, 29, and 32. For example, “Item 23: Never modify the arguments object” advises the reader not to modify the collection of optional arguments. In fact, it is well known that programmers have a reputation of taking advantage of unthinkable situations, and modifying the “arguments” object indeed goes against all good programming practices. It is an easy path that produces hard-to-maintain software code. The reader is therefore left with the question of how often such problems occur in practice.

While he author highlights some important points about JavaScript, this book is not about learning the language. Authors who wish to learn JavaScript might consider reading another book [1]. On the other hand, people who make heavy use of JavaScript will find this book valuable. However, finding a particular point treated as an item in the book must not be taken as permission to use it in your own code. The book is about working with the oddities of JavaScript, and should not be considered as carte blanche to employ these mechanisms in your own code. Be kind to the engineer who will maintain your code in the future.