Saturday, May 25, 2013

I saw David Tulig speak at indeed.com on Google Closure Tools.

On Wednesday, I stopped by the indeed.com office for an event they held. David Tulig spoke on Google Closure Tools which is yet another JavaScript framework. The most interesting thing about the closure stuff is that it offers three different ways to minify code:

  1. whitespace_only
  2. simple_optimizations
  3. advanced_optimizations

These grow progressively more intense with simple_optimization being the most akin to what you are probably used to in JavaScript minification and whitespace_only being a watered-down version in which just the whitespace in a .js file is trimmed away but otherwise bits of code (such as variable names) which could be shortened are left be. In advanced_optimizations chunks of the code base which are deemed to be unused are merely thrown away. advanced_optimizations also sanity checks your code with compilation safety. If you try to pass a node to something that wants a string and then attempt the advanced_optimizations minification, the compiler will freak out as a compiler should consistent with what everyone expects of type safety. The architecture is interesting. Modules "depend" on other modules in that they listen for events to be fired by them. Two dependent modules with a common parent will talk to each other through the parent. For A to speak to B, A will fire an event that the parent consumes. Somehow the parent then makes B aware too. I cannot say that I really get it without digging into the code. The code David showed off was of an AutoComplete feature for a search field and the module had both a text handler and a RPC (remote procedure call) handler. The text handler module triggered an event in the AutoComplete module which then ended up making the RPC handler act. The text handler and the RPC handler were thus loosely coupled. A drawing of dependencies does not necessarily look like a tree however as a lot of the low level mechanics are abstracted to modules which are used by more than one parent. An application (module) typically breaks into DOM, events, and styles modules and while the events module uses the object and array modules it is not the only module in the second tier to do so. Google has a canned tool for defining dependencies and not starving a module of a dependency which, as you might imagine, hinges on defining things in the right order. Use this utility for defining dependencies cleanly.

No comments:

Post a Comment