Raymond Camden shares how a recent project led him to integrate some workflow tools that helped him improve the quality of his JavaScript code.
- While writing the JavaScript, I ran into a few bits of code that felt repetitive and seemed ripe for optimization. I intentionally ignored those thoughts and focused on getting the code working. Premature optimization is frowned upon for a reason. Now that the code is released though, I think it makes sense to go back through and look for improvements to the code base.
- Obviously – and probably more sensible before the optimization, would be the use of unit tests. As this relies upon a remote service, writing tests could be problematic, but even a test that assumes that remote service is running perfectly would be better than no tests. Plus, if I write these tests first, I can then look into code changes and feel secure that I’ve not broken anything.
- I’m a big fan of JSHint and would like to run it over the code base and make sure it passes that test as well.
- I’d also like to ship a minified version of the library. To be honest, I’ve never done that before, but if I had to guess, I’d bet there is a command line program I could run to generate that.
- Finally, I bet I can handle running the unit tests, JSHint checking, and the minification, automatically via a tool like Grunt or Gulp.