When you're writing code alone, you have a lot of leeway. But when you start writing code as part of a team, you need to think harder about the decisions you make. This book will help you do that. When you write code in a team setting, will other developers be able to understand what you did? Did you organize your code in such a way that it's easy to adapt and extend? Will your code survive once you're gone? Maintainable JavaScript doesn't just recommend a set of guidelines, it examines guidelines being used and recommended by others in the industry, so you get a feel for what's common in well-run JavaScript projects. Save a copy of this book now. It's the only resource that focus solely on JavaScript conventions.
Nicholas C. Zakas is a front-end consultant, author, and speaker. He worked at Yahoo! for almost five years, where he was front-end tech lead for the Yahoo! homepage and a contributor to the YUI library. He is the author of Maintainable JavaScript (O’Reilly, 2012), Professional JavaScript for Web Developers (Wrox, 2012), High Performance JavaScript (O’Reilly, 2010), and Professional Ajax (Wrox, 2007). Nicholas is a strong advocate for development best practices including progressive enhancement, accessibility, performance, scalability, and maintainability.
Maintainable JavaScript by Nicholas Zakas (O'Reilly 2012) is a short-and-sweet little text on (as the cover says) "writing readable code". And by "readable code", Zakas means "code that other developers not named [YOUR NAME] will be able to read and make sense of and ultimately maintain". It goes beyond maintainable and readable code though--Zakas takes us on a tour of how to deliver high-quality JavaScript that is testable and maximally performant in production. If you look at Zakas' catalog, this subject is right in his wheelhouse, and the book reads like either a sequel to his 2010 [title: High Performance JavaScript] or else as a lengthy appendix toan expanded version of Chapter 24 of his 2012 [title: Professional JavaScript for Web Developers] (3rd edition). It's an opinionated book about formatting style, about programming conventions, and about ways of helping you (and your team) write code that is a lot less likely to blow up on you down the line.
Right off the bat: the target audience for this book is not advanced JavaScript developers. If you are an advanced JavaScript developer (or even many mid-level JS devs) then these are concepts that you are already familiar with. You've already dabbled in a style guide. You already know to minimize global variables. You already know to use feature detection. And there's a good chance you're at least linting, if not testing, if not doing both of those things automatically as part of your build. If that sounds like you, then you might want to take a pass. But before you do, give the table of contents a second glance. (If nothing else, you'll feel really validated.)
So who is it for? It's for novice and intermediate level JavaScript developers that want to get a better sense of what "readable" and "maintainable" code looks like. It's for folks that are plowing through the other "slim" JavaScript books in the O'Reilly catalog. [1] It's for technical managers who don't have a JavaScript background. It's for folks that want to start a book club for front-end devs and have spirited debates about ASI and how many spaces to indent when an expression continues on the next line.
As I worked through Part I ("Style Guidelines"), my initial impression was that Zakas was writing a how-to for writing JavaScript style guides. We have 44 pages of in-depth discussion on where to put curly braces, how many blank lines to use (and where), and what a proper comment looks like. Esoteric rationales to inform what (on the surface) seem like so much pedestrian banalia. ("Who cares what I name my local variables?") But by the end, there is a well-reasoned case made for all of the recommendations that will go on to appear in Appendix A.
Where the book becomes more interesting is in Parts II ("Programming Practices") and III ("Automation"). Again: the chapters that comprise Part II are going to seem like review for many seasoned JS devs: keep your JS and your mark-up loosely coupled; avoid global variables; keep configuration data separate from business logic; use feature detection instead of browser detection. As much of these may seem like review, [2] don't get cocky and skim it, either--there are some gems in there. (In particular I'm thinking of the chapter on Event Handling that spawned this interesting post by Ben Nadel.)
The chapters in the Automation section were my favorites. Zakas builds up a solid Ant-based [3] build system over the course of 7 chapters that includes validation and linting, file concatenation and gzipping, minification, documentation, and automated testing. As I've become highly interested in the build process, I was riveted by these chapters. Zakas at least touched on every topic in the automation/build topic that I would have wanted to see. But that being said: the operative phrase was "touched on"--I would have loved to see more on this subject. He provides a lot of excellent starter material, and Appendix B is a rich list of other jumping-off points, but it also seemed... shallow? Like he was just scratching the surface? This seemed especially true of the chapters on documentation [4] and testing. [5] [6]
All in all? I would strongly recommend this to folks that are new to JavaScript, but only a mild nudge to seasoned folks.
[3] Although, honestly, my first thought was: "Really? Ant?"
[4] Although I suppose I have lofty expectations for documentation. (A detailed glossary of what the different @keyword annotations are for etc.) This chapter is probably fine, it's my expectations that are messed up.
[5] I definitely think there could have been more on testing. There's like a page and a half on PhantomJS. Having played around with it a bit myself, I feel like it could have earned a chapter all to itself. Granted, I wouldn't want the whole book to be about testing (Grails in Action, I looking in your direction)--and since most JS books don't mention testing at all, I'm grateful to see it get at least the chapter that it did but... I could have used a little more.
[6] Also: Zakas implies that you need to run JavaScript tests in the browser and I just don't believe that to be so. If you're working with the DOM or BOM objects, then yes: he's right. But if you're otherwise following functional programming patterns, and have clearly defined arguments and returns, and you're avoid side-effects in your code... Well, you should be able to unit-test stuff like that without a full-blown browser at your beck and call.
------
Disclosure: I got a free copy from O'Reilly in exchange for writing a review as part of their blogger/reviewer program...
Covers quite a lot about writing good quality JavaScript code. Can be used as a complete resource for implementing your own JavaScript code style guidelines as well as learning about various build tools and other important bits of modern JavaScript development. Despite the fact that I've been doing web programming for nearly a decade I found interesting and unknown bits regarding JavaScript development in this book. Recommended!
This book is must read for every team that is working on bigger JavaScript project. The author has that kind of experience, he worked in the development of the Yahoo page and explains what practices should be followed in order the code to be scalable, readable and maintainable.
If you are experienced developer you may know the most of this stuff. I have experience in OO programming but I am relatively new in JavaScript so this book helped me to understand some practices and principles that are specific for JavaScript. In my opinion the part where the configuration for build, documentation tools is explained can be shorten because you have the specific tool documentation for that.
If JavaScript team reads this book before beginning of the project and implements the advices and practices written here it will have much easier job later in the project.
La prima parte di questo manuale è una estesa raccolta di best practices su come organizzare il codice, come suddividere gli script, come nominare le variabili, ecc.
La seconda parte copre quasi esclusivamente l'uso di tool esterni (per analisi statica del codice, raggruppamento, minificazione, ecc.) e Ant per automatizzare tutti i processi di deploy.
Se non avete mai letto manuali sullo stile di programmazione e non conoscete Ant, questo manuale è un must read, mentre se avete già basi di clean code, usate già jslint e soci, e conoscete già Ant, sarà fondamentalmente inutile.
Se avete già letto "Professional Javascript for Web Developers" (dello stesso autore) o "Javascript the Good Parts", la prima parte sarà abbastanza inutile, in quanto già coperta da entrambi, e la seconda parte potrebbe non valere il prezzo, soprattutto se non usate Ant.
(3.5) Some helpful stuff, still preferred JavaScript: The Good Parts (though it's less opinionated than that)
A lot of it is general good programming practices, but made more explicit in JavaScript. I wish he justified all of his coding conventions. I'd still recommend reading this though.
Great, easy and fast read for all JS Developers, especially when working in a team and when you're working out your own JS guidelines or learning about some strange parts of the language (applies to beginners as well as to advanced JS devs). Some parts are a bit outdated (e.g. Automation with ant; grunt was probably in its early stages that time), but they are easy to spot and skip.
A good checklist of areas to consider when thinking about how to write and maintain code. Alas the state of art in JavaScript mid 2016 has negated many of the concrete suggestions in the book. Likewise many tools mentioned in the automation section would not be used in a modern development workflow.
Started off strong but overall felt very light, none of the topics were covered in any depth. (To be fair this is a pre-release version of the book). I also would have preferred the Automation section to be tool agnostic, the focus on Ant was a real shame.
This book is awesome. If you now javaScript and you want to improve your code style habits I highly recommend this book. How ever this book is written when Grunt was not so popular like it is today, so part 3 automation is not that attractive and it is covering an other tool (Apache Ant).
The advice is generally really sound, the problem that I had with this book is that it uses ant for the build system, grunt would have been a much better choice. If this book is aimed at java developers then maven would have been better... personal preference I guess.
A very useful code convention for Javascript, I really recommend this book to all frontend developers, especially, to the one's that work on larger projects.