JavaScript: The Good Parts

JavaScript: The Good Parts

ISBN 13: 978-81-8404-522-2

By Douglas Crockford

O’Reilly Media, Inc.

JavaScript is a must know language for anyone who has to do anything with development on the web. If you are a hardcore fanatic type, who wants to adhere to a single language like PHP or JSP or Python (or any of them) for the back as well as frontend development, chances are you won’t be getting much far in the design side, and the developmental side too will soon saturate off at what it has to offer. JavaScript has been the de facto language of creating beautiful content on websites since a very long time. JavaScripts, as a good old Samaritan filled the shoes which Java was expected to fill. But like every language, this language too has its fair share of quirks and blunders. To err is human and languages are devised by humans only. So, it is fair to say that if we could dispense with the bad or ugly parts of anything, what remains is the good parts. This, is about those good parts of JavaScripts.

The author makes it explicit that the book is not for beginners to programming. This is a fine cautionary statement that he makes, since, I think JavaScript should not be anyone’s first tete a tete with the world of programming, go begin with something simpler, or rather, traditional. But he also makes it clear that it will be useful for programmers (like me) who have been programming in other languages and are by happenstance or by curiosity venturing into JavaScript. With the same cautionary note, I shall proceed to present my views on this book on my first pass. First pass, because it will be necessary to get back to it again and again if I am to learn and embody the good parts in the way I work.

JavaScript is an Object Oriented Programming language but does not belong to the classical family which boasts of members like C++ and Java. It is a prototypal language, its focus is not on classes but on objects. We don’t declare classes, we simply start using them, and what we use becomes an object. This book delineates the pitfalls and the advantages of such kind of language what kind of power can a coder wield when using this language the power to write good code, and commit horrendous blunders. It starts off with a brisk glance over the grammar and syntax of the language, the rules and the flexibilities; for example, the language is not strong typed and what keywords are allowed, what words are not keywords and still not allowed (NaN for instance). The author does so with the help of wonderful railroad diagrams. They might seem confusing at first, but get easier with familiarity, as I found out.

Then, it starts to delve into the crux of the matter in a succinct, yet explicit style. It is at points like these when I felt like I was on the losing side since I have had no good or formal exposure to OOPs before, only mild flirtations and flings that lasted a few days, or perhaps months. But then, I was reminded to the book on Design Patterns by the gang of four (which again is a kind of OOPs focused book but does not focus on any particular language and talks of general patterns that get into design methods worldwide). Some of the patterns, the author explicitly names, like the ‘Invocation pattern’, or ‘Constructor pattern’ while he sidles a few names while demonstrating their use with JavaScripts, for example, the Singleton pattern, which he refers to something as having closure.

This is a book that talks more of extracting the parts of JavaScript which work and create a small library for yourself which adheres to the patterns which are robust, and efficient. No, it doesn’t apply JavaScript to HTML or anything, it teaches JavaScript like a core language, not something ancillary designed to help HTML. Of course it is designed to work on HTML, but it isn’t designed for just HTML. It can do much more, and this book just opens up the perspective, a little.

What to expect of it? I have a hunch that I did understand something good out of it, at least I am confident that I can write some code in JavaScript while avoiding the pitfalls that are bred into JavaScript by its creators. It is like learning what to do by learning what not to do, if you cannot properly learn what to do. That looks like an ambiguous statement, but a first pass has given me only such kind of clarity.

So, if you have a background in programming in Java or C, or C++ or any other popular programming language, this book is a quick and clean introduction to JavaScript to you. You see, the chapters are just 100 pages with a good font size of 14 (I think). Next 40 or so are the Bad and Worst parts which explain what works in JavaScript and what doesn’t. For example, the coding style that I am currently used to, which I must change while working with JavaScript because it tries to autocorrect:

return{
<object attributes/methods>
}

Instead of

return
{
<object attributes/methods>
}

Since the JavaScript might just append a ; and make my statement

return;
{
<object attributes/methods>
}

Which isn’t what I want.

I hope to discover and remember more interesting snippets as I repeatedly refer back to this book as I learn. On a side note, I really did not understand the author’s fascination with Shakespeare quotes at the beginning of each chapter. Some of them didn’t even fit (according to me) and were there just because they included that keyword. But, if he has read all of those works to find us the best of two worlds, Shakespeare and JavaScript, kudos to the effort!