Re:Google releases Closure, the tools behind the JS geniuses
by asher on Monday November 09, 2009 @10:27PM
(#932373)
Thoughts so far:
The templating system is interesting. It does something I have not seen before: You can define one template, then execute it server-side (in Java only) and/or client-side (compiled into Javascript).
To achieve this, the template language is quite restricted. It seems that we could write interpreters for this language in Ruby, Python, etc.
Also, we could write a compiler back-end which generates C to run inside nginx or Apache; this could yield a high-performance templating system.
Here's an example template I made. Note that the "javadoc" portion is mandatory and is parsed by the compiler.
/**
* show a table
*
* @param data array of values
* @param ncols num columns
*/
{template .vvtable}
<table cellspacing=10><tr>
{foreach $d in $data}
<td><div style="background-color:#f00;padding:5px">{$d}</div></td>
{if not isFirst($d) and index($d) % $ncols == 0}
</tr><tr>
{/if}
{/foreach}
</tr></table>
{/template}
Re:Google releases Closure, the tools behind the JS geniuses
by psranga on Monday November 09, 2009 @07:19PM
(#932096)
Does it provide any support for avoiding/detecting Javascript "memory leaks" which are easy to create with closures and anonymous functions?
That's what interests me the most.
The stuff they have here for annotating types (love the type expressions), equivalent of #define are major conveniences to ease development. And long overdue. So thanks, Google.
Re:Google releases Closure, the tools behind the JS geniuses
by mpk on Monday November 09, 2009 @08:42PM
(#932216)
Thank you psranga for being the only one in here to make a technical comment.
Leak profiling in JS is a pain. I wasn't really expecting Google to provide an answer here because all their apps contribute to wasted heap space too.
Google's answer (as far as I can tell) is just to push it back to the browser. In their case, use Chrome, which uses a separate process for each page.
Chasing JS leaks has to be one of the most frustrating exercises ever. I ended up using a windows tool for analyzing jscript.dll and cross-referencing this with a custom spidermonkey build (with lots of print statements in the source).
Anything less than insight to this problem I'm going to take with a grain of salt.
Re:Google releases Closure, the tools behind the JS geniuses
by joeyo on Monday November 09, 2009 @08:42PM
(#932215)
> Does it provide any support for avoiding/detecting
> Javascript "memory leaks" which are easy to create with
> closures and anonymous functions?
I don't understand this. Do closures leak because of buggy javascript implementations or is there something about them that fundamentally prevents the interpreter from being able to tell when to garbage collect them?
Re:Google releases Closure, the tools behind the JS geniuses
by vl on Monday November 09, 2009 @07:16PM
(#932089)
It would be interesting to see what gives developer better productivity in the long run: Closure or GWT?
I'm big fan of GWT myself, and one of the reasons is that it allows me to build bigger projects: my JS projects always reached maintainability problems sooner than GWT projects.
Re:Google releases Closure, the tools behind the JS geniuses
by nym on Monday November 09, 2009 @05:56PM
(#931949)
The Closure Compiler is the big news. As the article says, it turns your regular JavaScript code into compact, high-performance JavaScript code. This is some of the magic behind Google Maps, Gmail, and I assume Wave.
This is a very big deal for JavaScript developers because it is like having JSLint, YUI Compressor, and Chuck Norris rolled into one.
Re:Google releases Closure, the tools behind the JS geniuses
by enneff on Monday November 09, 2009 @10:04PM
(#932328)
"it turns your regular JavaScript code into compact, high-performance JavaScript code."
It won't actually make your JavaScript much faster, if it does at all. The major benefits are the exclusion of unused code, and code in-lining where possible. This helps a lot in terms of cutting down loading times, but your code is still only really going to be about as efficient as it was before.
Re:Google releases Closure, the tools behind the JS geniuses
by swolchok on Tuesday November 10, 2009 @12:00AM
(#932472)
Not true if you use objects as namespaces -- it is capable of reducing a.b.c.d to one access, particularly with inlining, and this construct has a runtime cost in JS.
The templating system is interesting. It does something I have not seen before: You can define one template, then execute it server-side (in Java only) and/or client-side (compiled into Javascript).
To achieve this, the template language is quite restricted. It seems that we could write interpreters for this language in Ruby, Python, etc.
Also, we could write a compiler back-end which generates C to run inside nginx or Apache; this could yield a high-performance templating system.
Here's an example template I made. Note that the "javadoc" portion is mandatory and is parsed by the compiler.
That's what interests me the most.
The stuff they have here for annotating types (love the type expressions), equivalent of #define are major conveniences to ease development. And long overdue. So thanks, Google.
Leak profiling in JS is a pain. I wasn't really expecting Google to provide an answer here because all their apps contribute to wasted heap space too.
Google's answer (as far as I can tell) is just to push it back to the browser. In their case, use Chrome, which uses a separate process for each page.
Chasing JS leaks has to be one of the most frustrating exercises ever. I ended up using a windows tool for analyzing jscript.dll and cross-referencing this with a custom spidermonkey build (with lots of print statements in the source).
Anything less than insight to this problem I'm going to take with a grain of salt.
Reference counting GC is the problem, not closures.
I'm big fan of GWT myself, and one of the reasons is that it allows me to build bigger projects: my JS projects always reached maintainability problems sooner than GWT projects.
I think sexy was a bit of sarcasm.
EDIT: spelling ..
edit: it seems the library is similar in terms of dom manipulation, but the compiler and templating system seem to be the major differences?
This is a very big deal for JavaScript developers because it is like having JSLint, YUI Compressor, and Chuck Norris rolled into one.
It won't actually make your JavaScript much faster, if it does at all. The major benefits are the exclusion of unused code, and code in-lining where possible. This helps a lot in terms of cutting down loading times, but your code is still only really going to be about as efficient as it was before.
But do GWT and Closure use the same technology, that I don't know.