Now available: Maintainable JavaScript
I’m happy to announce that my latest book, Maintainable JavaScript, is now available in print. Thanks to the folks at O’Reilly, the ebook was released as a preview last month, but now all the edits have been completed and the book is officially done. I’m very excited about this book, even moreso than some of the others, because it’s quite different than any I’ve written before.
One of the reasons I’ve very excited about this book is because it’s the first book that I’ve conceived of and written entirely on my own. Each of my previous books developed through others. Professional JavaScript wasn’t the book I set out to write, but it was the one I agreed to write. I worked on the outline with Jim Minatel before finally putting the book together. Professional Ajax was entirely Jim’s (brilliant) idea. I even fought him about it and at first declined to write it. Lesson learned: Jim is the man. For High Performance JavaScript, I was approached jointly by Yahoo! and O’Reilly to write it.
Maintainable JavaScript, on the other hand, grew out of a talk I gave when I first started at Yahoo! (the embarrassing video is available in YUI Theater). It was my first ever talk, and so it was very rough. I also spilled my water right on top of my laptop about halfway through, so I was freaking out that the computer might explode. In any event, last year I was asked to reprise the talk for PayPal, and then received other requests to give the talk. In redoing the presentation, I noticed that almost everything I said in the first version still held true (aside from a few personal preferences).
In December, I kept thinking about better ways to explain the topics, and before I knew it, I had a whole book outline sketched out and was digging into writing. The book almost wrote itself, as I blasted out 45 pages on the first day. It wasn’t long before the book was written and ready to go.
I’m also excited about this book because it’s largely an opinion book. I’m telling you about my experience writing enterprise-level JavaScript in my career. Because of that, I get to share stories from my personal experience as to why some practices are better than others. To put it simply, I use the word “I” in this book, and that is a fantastic feeling. It gives the book a more personal, conversational tone than my others.
Yeah, yeah…what’s it about?
Maintainable JavaScript, like my talk of the same name, is all about writing JavaScript that will continue working for five years. Code that remains working for five years might seem like a pipe dream with the rapid evolution of browsers and web technologies, but it’s not only possible, it’s important to your team. Your code should outlive your presence on any given job, and further, it should be able to be worked on by others with ease.
To that end, Maintainable JavaScript focuses on three things:
- Code Style – yes, everyone loves a good discussion about code style guidelines. I compare and contrast style guidelines from several popular style guides and add in my own opinions on what makes a good code style. In the end, style is personal, and all that really matters is that everyone on the team writes code in the same way. This part of the book takes you through all of the important stylistic considerations that you should put into your style guide (a copy of my personal style guide is included as an appendix).
- Programming Practices – these go a step further than code style and instruct you on common solutions to simple problems. Programming practices are algorithms and approaches rather than syntax. Browser sniffing is a programming practice, for example. This section goes through several practices that are either good or bad, and explains why using real-life situations.
- Automation – the way that you ensure style guides are followed and other errors don’t creep in over time. By having automated ways of processing and verifying code, you prevent code rot and ensure that new code is always following established guidelines. This section uses Ant as an example of how to build out an automation system that can validate, minify, concatenate, and test your code.
Unlike my other books, I believe the tips and techniques in this book will remain relevant for a long time to come. As I said, it started as a talk in 2007 and pretty much everything I mentioned is still relevant, so I hope the tips will continue to be relevant going forward. I hope you enjoy it!
Disclaimer: Any viewpoints and opinions expressed in this article are those of Nicholas C. Zakas and do not, in any way, reflect those of my employer, my colleagues, Wrox Publishing, O'Reilly Publishing, or anyone else. I speak only for myself, not for them.
Both comments and pings are currently closed.




7 Comments
I believe in your book you incorrectly attribute detecting array type to Juriy Zaytsev (Kangax). I think this should be attributed to Mark Miller (Miller’s device).
See Google source code:
http://closure-library.googlecode.com/svn/docs/closure_goog_base.js.source.html
Search for “Mark Miller noticed”
Les on May 29th, 2012 at 9:55 am
Thanks for the feedback, but I believe my attribution is correct. Kangax wrote the first article on this technique, and from that, it became popular. I can’t go on private conversations that happened within the confines of different companies; I can only go with what was published.
Nicholas C. Zakas on May 29th, 2012 at 10:02 am
I’d like to point out an obscure IE6 and IE7 bug in the isArray function.
The call below will display [object Object], not [object Array], so
the isArray() call will fail in this case.
if (window.opener) {
var test = Object.prototype.toString.call(window.opener.testArr);
alert(test);
}
See this isArray discussion, search for ‘Richard Cornford explains’:
http://perfectionkills.com/instanceof-considered-harmful-or-how-to-write-a-robust-isarray/
Les on May 29th, 2012 at 10:29 am
Every book you put out is awesome. I can’t wait to read this one, too!
Jason on May 29th, 2012 at 1:27 pm
Great! can’t wait to read this. Congrats!
Manish Ranade on May 29th, 2012 at 9:45 pm
I am Chinese ,I really like your book! I can’t wait to read this one!
taiji on May 30th, 2012 at 7:03 pm
I’ll be sure to add this one to my bookshelf.
Hans on June 1st, 2012 at 9:20 am
Comments are automatically closed after 14 days.