Interviewed by Adam Flaherty (O’Reilly)
1. Why is your book timely – what makes it important right now?
JavaScript is really hot right now. It’s the most-used and most in-demand programming language in the world, and the upward trend that got us here is still growing. The realm of possibilities with JavaScript is expanding right on with it. These days, the browser is the platform for almost every type of app, from productivity tools to fully immersive 3D video games. It’s also expanded into the back end, where it powers production servers for the biggest (and smallest) companies in the business. Learning JavaScript and Node will put you on the most wanted list of thousands of technical recruiters.
2. What information do you hope that readers of your book will walk away with?
Most JavaScript professionals had limited experience working with JavaScript in full scale applications when I started working on the book. There were few other books that talked about modern JavaScript techniques, or how to use JavaScript to build large applications. I want the readers to walk away with a better understanding of modern application architecture and programming techniques, from unit testing to front end separation of concerns (like MVC), to writing web services in Node. It’s more of an overview of each area than a deep dive into any particular one, but it should give an experienced programmer enough examples and insights to get started, and to have some idea of where to go next.
3. What’s the most exciting/important thing happening in your space?
It’s so hard to say there’s a most exciting thing happening in the JavaScript world. So many things are taking off at the same time. Node is exploding. It’s being used for everything from web servers to robotics, including artificial vision and audio processing.
WebGL games and demos are showing technology that would have been impressive on native desktops five years ago. It might be another five years before web games can compete with the technical capabilities of today’s desktop and platform games, but it’s clear that’s the direction we’re headed in.
That’s really exciting for more than just the game community. It will also impact consumer expectations of what’s possible with website user interfaces. I think we’ll see the shift first in entertainment properties and ad agency content, but the web experience is definitely going to get more immersive in the very near future. It’s already starting to happen.
Of course, all of that will benefit from the dramatic changes coming to the JavaScript language itself. ES6 is well on its way to adding some very cool features to JavaScript. Destructuring assignments, generators, rest parameters, and array comprehension are all exciting and welcome additions to the language. It may be a while before we can freely use these new features in our browser code, but some of them are available for experimentation right now.
4. Please include a short list of 5 tips and tricks.
1. Write short functions. In JavaScript, you’ll have some long functions that are unavoidable (such as wrappers for module scope), but the stuff that’s actually doing all the work should be really short. Aim for les than about a dozen lines. Short functions are more flexible, more reusable, and much easier to read. Keep it simple.
2. Unit test all of your surface-area code. That means, if you export a function for somebody else to use, that function should be covered by tests. Make sure you remember to test for edge and error cases.
Unit tests are more than just an assurance that your code does what it’s supposed to do. They can also act as an implementation checklist to help you while you’re developing your code. Of course, the best part about unit tests is that code is a changing, ever evolving thing. Unit tests give you the assurance that when you go in and make changes, whether they’re bug fixes, feature additions, or refactors, you’ll know right away if anything goes wrong. Just run your test suite and make sure the tests still pass.
Unit tests teach you discipline, and provide you with a deep debugging insight into your code. It really helps to know what still works and what doesn’t when a bug creeps in, and short of littering your code with all sorts of logging statements, unit tests give you better insight into that than almost anything else you can do. I know there are lots of developers on the fence about this, or just not sure where to begin. Here’s your kick: It’s worth the effort to figure it out.
3. Don’t get attached to any particular implementation of your code. A month from now, you’re going to wish you’d done things differently. Get used to it. Once you’ve set down your code, forget about the pride in your implementation. The important questions are, “does it do the job?” and “will it be easy to change?” — emphasis on the second question.
“Code by itself almost rots and it’s gotta be rewritten. Even when nothing has changed, for some reason, it rots.” – Ken Thompson
4. Learn the native capabilities of JavaScript, and take advantage of them. In particular, functional programming techniques (lambdas / closures / partial application, the words sound more complicated than the techniques actually are), object literals, dynamic object extension, prototypes, factories, and fluent APIs for objects (lots of methods could be improved if they returned this). When used together, I call this “fluent style JavaScript”, referring to fluency in a language. I didn’t invent it (jQuery is written in mostly fluent style, for example). It’s just what people who are fluent in JavaScript do.
5. Really learn prototypes. No, I don’t mean learn how to assign things to a constructor prototype, I mean really learn how to use prototypes to full advantage. For more on why prototypes are so cool, and a simple tool that will help you use them effectively, see this post on my blog: Fluent JavaScript: Three Different Kinds of Prototypal OO.
Follow me on twitter: @_josiah_king
Join me on Google+: https://plus.google.com/u/0/113541005774136102412/posts/p/pub?cfem=1
No comments:
Post a Comment