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 |