Skip to content

Comment on Google Closure: How not to write JavaScript

Comments

Time in web applications is not used looking up array lengths - it's used in IO, layout, and DOM manipulation. If iterating through arrays was found to ever be a noticeable issue in practice, the Closure compiler could just be modified to emit more efficient code. That's one of the advantages of having the compiler - you don't have to make a convenience/readability trade.

Closure was not thrown together by novices new to the language. It was started by Erik Arvidsson and Dan Pupius, two JS hackers that have been doing this kind of work longer than just about anyone else. Its differences from other libraries aren't the result of ignorance, they're mostly the result of conscious tradeoffs to make compilation more effective.

Edit: Oh, and the string thing... If you ever do

  new String("foo")
in JavaScript, you're doing it wrong.

Here is an example of a real-world performance bottleneck that was discovered by the closure team:

http://pupius.co.uk/blog/2007/03/garbage-collection-in-ie6/

> Time in web applications is not used looking up array lengths - it's used in IO, layout, and DOM manipulation.

Unless you're implementing a cross-browser stable sorting algorithm for manipulating tables 50,000 rows long or longer (that was exactly my most recent project). Don't say "it should be done on the server" because that statement is true only as long as everybody keeps writing bad Javascript.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.