views:

8829

answers:

8

Considering

  • business background
  • community support
  • available extensions
  • default set of features
  • simplicity of use
  • and reliability

why do you prefer one over the another?

+49  A: 

I'll try to add my piece of information.

More than another JS lib

As I understand it, Google Closure is not only another JS library, but it is also a set of tools that will allow you to optimize your JS code. Working with jQuery gives you good tools and a lightweight library, but it does not minify your own code. The Closure compiler will. The closure inspector may also be useful, as sometimes minified code has a different behavior than the original one, and is a pain to debug. It integrates with Firebug and support unit tests, which are both developers' best friends nowadays.

Documentation

I guess that as any new library VS a well established one, it will lack the availability of tons of extensions and tutorial that jQuery has. However, being pushed by Google should ensure that support and reliability will be both pretty good. The current documentation and tutorial both seem really good, too.

Features

The features of Closure look decent, though, and its modular architecture is promising, too. I guess Google has been using it internally for a long time, which means that you could expect all basic features (and more) to be implemented, and probably in a very optimized and scalable way. They are trying to present it as the STL of JavaScript, so they should have polished it.

After looking at the features more closely, it seems that this may be a step forward for web-applications development compared to existing libraries as jQuery. It guess it benefits internal developments at Google, but things like detecting the online state (see goog.events.OnlineHandler), easy integration of AJAX requests and JS actions in the browser history (see goog.History), or the legions of great widgets they provide (see goog.ui package) may help all of us building even more awesome webapps ;) !

It comes with templates features that integrates with Java (who said GWT ?), so this may also be another plus for Closure.

Ease of use

Finally, it looks pretty simple to use. The syntax may be a bit more verbose than the short $ jQuery function, but with IDEs and auto-completion, it's not a real problem. Moreover, I'd say we can expect a good integration in IDEs like Eclipse, coming from Google.

EDIT: as requested, let me say a few words about the GWT reference. Google Web Toolkit is a Java library that allows to create AJAX-enabled web interfaces and that generates (and optimizes) the required JavaScript code. As Google Closure allows to create Templates that can be used both client- and server-side (using JavaScript and Java), my guess is that it will soon be possible to use them jointly (if it's not already the case).

Wookai
Detailed and meaningful answer, thank you. Could you please explain what that reference to GWT means? I'm afraid I didn't get that.
pestaa
I think you should also mention the template library (Soy) in your "More than" section. The same template file can be used in both server (Java) side and client side. Really nice implementation IMO. Means we can just send down JSON in AJAX queries rather than sending down HTML - saves bandwidth.
Frank Krueger
I just discovered a critique against Closure, but perhaps it's just FUD: http://www.sitepoint.com/blogs/2009/11/12/google-closure-how-not-to-write-javascript/
nalply
The critique isn't FUD, and thanks for the link. The critique is focused on how the javascript code isn't optimal everywhere. This may be valid, but it misses the larger point. As I understand it, Closure targets really complex JS applications (on the scale of GMail), and that has some consequences - such as not every line being optimal since everything isn't written by a single brilliant coder. But conversely it might scale further as a software engineering framework.
Peter S Magnusson
@nalply that article does mention a whole number of pretty genuine performance issues with goog closure. I'm not a JS expert but I was actually thinking of using closure and that article convinced me not to.
giddy
@giddy: this article has been criticized quite a lot, and in my opinion you shouldn't worry about it too much: it's mostly just nit-picking on details that won't matter in most environments. No one cares about the "slow loop" if not iterating tightly on tens of thousands of elements, and the rant about arrays is completely ridiculous (feel free to do your own benchmarking on jsfiddle or jsperf). There are imperfections, but its maturity by **design** AND by **performance** is still - and again it is only my opinion - very suitable for enterprise development.
haylem
@giddy: Also, This critique is fairly old and there's been modifications to Closure since then. For a reference, Mike Bolin just released a book at O'Reilly, which I found a decent introduction (though sometimes obviously a bit-biased in favor of Closure, it also does pin-point some shortcomings). Your best bet to know if it's good is to try it out, and have a look at the code for yourself. You can always find stuff to nit-pick about in anyone's code, but to produce a *free* toolkit (library + compiler + templates + linter) with this degree of maturity is still an achievement.
haylem
A: 

The Google Closure Library allows you to compile and optimize your JavaScript. It's not a library like jQuery is. jQuery is something that provides you with functions that allow you to write your own javascript faster.

Google Closure would help you make your own javascript code minimized to allow for a speedier delivery over the Internet.

Long story short, Google Closure is a tool while jQuery is a library similar to Prototype.

Tereno
That is not exactly true. Google Closures also comes with its own library that is similar to jQuery and that provides functions and utilities to write your own code : http://code.google.com/closure/library/docs/tutorial.html
Wookai
Ah ok! Thanks for correcting me!
Tereno
+1 For trying to be helpful :)
Andomar
you deserve -1, not -3 :(
Brandon Thomson
+1  A: 

Maybe I'm not getting jQuery, but I haven't seen a real UI widgets collection there (there are plugins, yes, but you never know how well-tested they are and often there is no clear winner and/or the plugin lacks documentation).

Closure has, among other things, a widgets collection (see the demos tab), including, say, imageless buttons used in gmail.

More generally, it has more functionality implemented as part of the release. It may not be a big thing, but I get annoyed with the sea of jQuery plugins when I'm looking for something as simple as a ajax history module or autocomplete.

Overall it's a huge library + set of tools and I'll be getting acquainted with it just to know what's available.

Nickolay
jqueryui.com is the official ui widgets collection
Jourkey
yeah well, judging from the site it has 6 widgets: Accordion Datepicker Dialog Progressbar Slider Tabs
Nickolay
I've used jQueryUI and I thought it was very weak. It hardly even seems to be in development. When was the last time a new widget was added. It may be the official widgets collection, but anyone looking for a widget to use with jQuery is better off just googling for third-party jQuery widgets.
Nosredna
jQueryUI isn't just a set of javascript widgets, it has a great css framework as well. Its been a great tool for me in styling CRUD/admin pages. Plus many of those Closure "Widgets" are 1-2 liners in jQuery, not even worth writing a plugin for.
Jace Rhea
+8  A: 

In my brief look at the API I find the differences between jQuery and Closure to be striking.

jQuery is basically just a simplified way to do many frequent operations in a cross-browser way.

Closure is a framework that is very new, in that they provide a cross-browser way to use the <canvas> tag, for example, and they have added new events.

So, this is adding onto what we typically do with javascript, they are taking many operations that people want to do and putting them into the API.

For example, they have an event to tell if the online state has changed. So you can tell if the system is online.

They have javascript functions that use tools such as Google Gears, which continues with the fact that they have extended what can be done with Javascript.

It will take me a couple of days to digest all the changes, but I can see that this could have a big impact on web applications that can be developed.

James Black
A: 

..I'm hearing that Closure has some serious coding holes : see this article referencing the opinions Dmitry Baranovskiy, the creator of the Raphaël and gRaphaël JavaScript libraries : http://www.sitepoint.com/blogs/2009/11/12/google-closure-how-not-to-write-javascript/

love to know what other people think of this!

zack
The SitePoint articles seems really snarky to me. After reading the article, I came away feeling like Dmitry was trying awfully hard to force his problem domain on others. If micro-optimizations enhance the performance of his library, great for him. That doesn't necessarily mean they will do the same for a library that has been created to scale with gmail, etc. Articles such as this one often leave me with a sour taste in my mouth. Not all problems are created equal ... and not all solutions are created black and white.
Jason Leveille
This article is bad. Very bad. On top of the micro-optimizations that Jason called out, the author goes on to say that closure would cause memory leaks by using the memoization feature to, for instance, cache the results of the mouse position.In this case, not only would that *not* cause a memory leak, but it demonstrates a complete lack of understanding of what memoization is and how it works.
Jonathan Arkell
These two demos don't appear to work in my firefoxhttp://closure-library.googlecode.com/svn/trunk/closure/goog/demos/depsgraph.html and http://closure-library.googlecode.com/svn/trunk/closure/goog/demos/color-contrast.html
Evgeny
I found that lot's of demos fail in FF3.0.4.. Maybe Dmitry has a point.
Evgeny
http://webreflection.blogspot.com/2009/11/google-closure-im-not-impressed.html
Evgeny
http://almaer.com/blog/getting-closure-dont-just-use-it-dont-just-abuse-it
Evgeny
+1 Doesn't answer the OP's question, but glad this was brought up.
Matt Luongo
+1. Most of the points in the article do seem valid. They're not "micro optimizations" if they are in a library function that gets called thousands of times. The switch block has to do a zillion object lookups before it can find a style element. That is not good javascript, micro optimization or not. Although the usage of the term "memory leak" is inaccurate, the memoization implementation can sure cause a memory hog if used in a way mentioned in the article.
Chetan Sastry
the point isn't whether the highlighted optimization was technically valid or not. the point was the significance of reviewing a large, complex framework from the perspective of a magnifying glass.
Peter S Magnusson
+1 Besides the micro-optimizations Dmitry shows some other points that might nitpicking but still clearly show that the quality is not on par with the almost perfect jQuery.
Tomas
+3  A: 

I just posted a pretty exhaustive article about Google Closure which answer this question on insideRIA: http://www.insideria.com/2009/11/google-closure-a-new-way-of-de.html

...Closure rulez! ^_^

Davide Zanotti
+1  A: 

I don't know much about jQuery, so my answer is not strictly speaking a comparison, but will try to answer with what I've learned about google-closure.

probably the best sources of information on google closure are project discussion group, wiki, doc pages, demos and a yet unfinished book by Michael Bolin that is now available from safari books site.

one thing I can tell right away - there is a steeper learning curve for closure vs jQuery but it may be well worth it due to the library's vastness, clear organization and the benefit of using it together with the compiler and the templating tool.

closure library in that respect is more like dojo than jQuery, and some concepts were borrowed from dojo, according to Michael Bolin.

google closure compiler uses JSDoc documentation system which simultaneously (if created by the programmer correctly) provides documentation and enables catching many errors at compile time.

while function names are more verbose than jQuery's, the compiler shrinks the code (using various optimization tactics) and the type checking will save a considerable time debugging the code, so time typing in the longer names is probably not an issue. At the same time longer names add readability.

library supports browsers running in the quirks mode so that scripts could be embedded by other sites using "quirky" html

library works with (but does not depend upon) a javascript templating system called soy that simplifies filling documents with content.

like jQuery google closure allows traversing dom structure with the string-based queries using a dedicated component of the library.

closure library relies on dot-delimited namespaces more like Java - a very strong organizational feature.

using such namespaces will incur overhead in uncompiled code, but in the compiled code those things are replace with short variable names.

Evgeny
+1  A: 

I'd say let us consider the history of Google's other announcements first, and then contemplate the "support" they get. Google rocks with search, with advertising, Maps, and Gmail. The rest? Meh. Let's see google support this project a little bit. Anybody using Wave? Buzz? Gears? Orkut? ( except in Brazil of course ) I love Google, don't get me wrong. We both want the same thing:

A standard web reachable in all places via HTTP.

However, they do tend to come with flashy announcements, lots of hype, but then the projects slip back under the waves of the web like Excalibur did after Arthur...

So my answer would be: JQuery. Better tutorials and more developers means doing stuff today.

chiggsy
I already began to doubt in Gmail, I'm slowly moving my team away from it. And I hate Docs as well. The current decade is going anti-Google I guess.
pestaa