Create an Account
username: password:
 
  MemeStreams Logo

MemeStreams Discussion

search


This page contains all of the posts and discussion on MemeStreams referencing the following web page: Truly beautiful code: JSMin. You can find discussions on MemeStreams as you surf the web, even if you aren't a MemeStreams member, using the Threads Bookmarklet.

Truly beautiful code: JSMin
by Acidus at 1:40 pm EDT, Jul 31, 2008

I've been reading Crockford's JavaScript: the Good Parts and am enjoying it enormously. But I'm really impressed by the code this man creates.

Just look at the C source code from JSMin. Over the last few years I've written a number of tokenizers and parsers for HTML and JavaScript so I know what my version of JSMin would look like:

* An enum defining states
* a big while loop iterating through a character array
* currChar and nextChar variables
* a big switch block for the state with nested if/then/elses or switch blocks

Crockford's JSMin is just... elegant. The way he shifts values back and forth between two char variables to hold last, current, and next char values. The way he processes string literals with a for loop that immediately does a put which allows him to simplify handling escape sequences inside of the string literal. The fall through in the action() function.

I debugged through the code many times late last night was was just speechless over how powerful yet compact this code is. It's subtle and beautiful and artful all at the same time. Truly beautiful code!


 
 
Powered By Industrial Memetics