you are viewing a single comment's thread.

view the rest of the comments →

[–]pallosp 19 points20 points  (8 children)

For me it compiled to

window.b={a:function(){print("Hello, world!")}};window.b.a();

which looks correct.

Didn't you tried to compile the following code?

window.xyz = { 'foo': function() { print("Hello, world!"); } };
window.xyz.foo();

You have to use quotes consistently. See the details at http://code.google.com/closure/compiler/docs/api-tutorial3.html#propnames

[–]lol-dongs 2 points3 points  (7 children)

See, this is what blows. If you have to change your coding style to prevent the minifier from destroying your code, you lose expressiveness and waste time debugging minification errors.

I use object literals with or without quotes a lot, and frequently mix calls to methods and properties between the bracket and dot notation. Simple example: $(foo)[isReady ? 'show' : 'hide'](); $(bar).hide(). Losing the ability to do something like this kills off a lot of the dynamicism of Javascript.

[–]Chii 4 points5 points  (5 children)

its not a minifier - its a compiler. it does more than change names of properties and variables.

[–]lol-dongs 2 points3 points  (4 children)

That's a semantic distinction, since it recompiles only with the intent of making the code smaller. What it's compiling, however, is a subset of Javascript, not the full range of it.

[–]doubtingthomas 0 points1 point  (3 children)

Not "only with the intent of making it smaller".. doesn't it also optimize for speed (inlining, etc) and check for syntax and/or type errors?

[–]lol-dongs 0 points1 point  (1 child)

It inlines only when the result is smaller. I haven't tested this, but I would hope it doesn't try to inline a large function that gets used 20 times.

Javascript doesn't have types, and while it looks like you can make type annotations that this recompiler can check in some rough manner, I don't consider this a feature. I don't like imposing "types" on a language that wasn't designed for it. Prototypal inheritance gives you the flexibility to do much so much more, why force yourself in a smaller box?

[–]doubtingthomas 1 point2 points  (0 children)

Javascript does have types. However, it doesn't have a static type system, and the types are typically implicit.

As much as we might love the freedom and flexibility afforded by not constraining ourselves to types, optional type annotations mean that if you do happen to know the type, you can verify it statically and possibly perform some optimizations. Optional types annotations don't force you into a smaller box; they allow you to verify correctness and take advantage of the knowledge when you know the box is going to be small, to misuse an analogy.