JavaScript Condenser



Conventionally, the condenser of the refrigeration system is either a plate type heat exchanger or shell and tube type heat exchanger. Circulating water from the secondary circuit rejects heat through an open loop cooling tower. The heat exchanger acts as an isolation point to maintain two independent circuits. The C414 XLII multi-pattern condenser microphone offers a choice of nine polar patterns for the perfect sonic capture for every application.

I've been coding some more advanced JavaScript applications lately and they've made me think a lot about coding styles. More specifically: shortness of code vs. readability.

My Mindset

©2004-2010 Javascript Compressor - Version 2.0 A Lunarmedia website. Condenser is a config-driven database subsetting tool for Postgres and MySQL. Subsetting data is the process of taking a representative sample of your data in a manner that preserves the integrity of your database, e.g., give me 5% of my users.

I can be a conflicted developer sometimes, so here are a few thoughts that go through my mind:

  • 'Tools like the YUI Compressor will compress my code enough.'
  • 'Sure YUI Compressor will shorten the code but it wont address shortening strings as arguments.'
  • 'With broadband internet, a few KB really wont matter.'
  • 'With mobile bandwidth constraints, I need this JS file to be as tiny as possible.'
  • 'I want this app to be easy enough for me to step into and understand again within 5 minutes.'
  • 'I want to be able to reuse some of this code in future projects without a bunch of hassle.'
  • 'How easy is it to judge 500 feet? If I stay a reasonable distance away from Christina Ricci, can they definitively prove I broke the restraining order?'

A Quick and Easy Example

Take the following verbose code snippet for example:

Though the snippet is very readable, it can be shortened quite a bit:

The above case shows a sacrifice of readability for the sake of short code. It would be easy to gloss over the 'setStyle' added to the parent. All things considered, which is better for you?

The String Concern

String literals aren't addressed by the YUI Compressor. So the following snippet..

..becomes..

Even though the 'display' and 'text' strings are used twice, they aren't shortened/replaced by a variable. Since we're foregoing readability by using the YUI compressor and only desire to have the shortest code possible, I feel like the above is a major fail.

Condenser

The String Compromise

When extreme shortness of code with readability is important, I'll take string literals and create variables with their same name at the very top of my application. Doing so keeps my variables readable when coding and allows YUI to really crunch the code. Here's the before:

.and the after.. Little mouses encyclopedia download free.

Awesome -- the code is still readable and frequently used strings can be compressed. Our code's compression ratio for this block alone becomes 37% -- a very significant number

Object Methods: Too Much?

Javascript Condenser Function

JavaScript Condenser

You could stake it a step further by using Array-style syntax and variable methods to assist the YUI Compressor. The before:

..and the after..

Javascript Condenser Interview

Condenser

Too much? I suppose it depends on the skill lever of the coder and the desire to make the code short.

What Do You Think?

Javascript Condenser Tutorial

What are your thoughts on the epic battle between readability and code compression? I think it really depends on the developer but I'd love to hear your thoughts!