Create an Account
username: password:
 
  MemeStreams Logo

Truly beautiful code: JSMin

search

Acidus
Picture of Acidus
My Blog
My Profile
My Audience
My Sources
Send Me a Message

sponsored links

Acidus's topics
Arts
Business
Games
Health and Wellness
Home and Garden
Miscellaneous
Current Events
Recreation
Local Information
Science
Society
Sports
Technology

support us

Get MemeStreams Stuff!


 
Truly beautiful code: JSMin
Topic: Technology 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!

Truly beautiful code: JSMin



 
 
Powered By Industrial Memetics
RSS2.0