简体   繁体   English

Google Web Toolkit对开发复杂的javascripts有用吗?

[英]Is Google Web Toolkit useful to develop complex javascripts?

我非常喜欢javascript框架,特别是jQuery。我一直想设计像“plurk.com”这样的网站,但我知道它需要非常庞大的javascript.so关闭我。但是因为我来了解GWT,我我真的想测试它,并想问你是否使我们的工作比使用javascript或其框架更容易开发复杂的东西。你更喜欢哪一个?

I think a few of the answers on this question are quite un-informed, and I suspect that the people answering them have never used GWT on large scale projects. 我认为这个问题的一些答案是非常不明智的,我怀疑回答他们的人从未在大型项目中使用过GWT。 Yes GWT is a great way to do large AJAX websites, and for large complex sites, involving a back end as well, it kicks things like JQuery up and down the park. 是的GWT是一个很好的方式来做大型AJAX网站,对于大型复杂网站,也包括后端,它在公园上下踢JQuery之类的东西。 The way I always look at it is that javascript on it's own is great for doing small client side things. 我一直看待它的方式是它自己的javascript非常适合做小客户端的事情。 When you need to do something more complex (like dynamic fields, popups, animations) you bring in something like JQuery or Prototype. 当你需要做一些更复杂的事情(比如动态字段,弹出窗口,动画)时,你会带来像JQuery或Prototype这样的东西。 When you want to take it one step further you go with GWT. 如果你想更进一步,你可以选择GWT。

People assume that because you write it in Java, it's designed for back end developers to do front end development. 人们认为,因为你用Java编写它,它是专为后端开发人员进行前端开发而设计的。 It's not. 不是。 Java is simply the language that they chose, mainly because it's widely used, statically typed and there are lots of good editors out there for it. Java只是他们选择的语言,主要是因为它被广泛使用,静态类型,并且有很多优秀的编辑器。

I don't buy the leaky abstraction theory either, it doesn't try to fully abstract out the HTML elements, as it gives you direct access to both native javascript and the DOM if you choose to use those. 我也不购买漏洞抽象理论,它不会试图完全抽象出HTML元素,因为它可以让你直接访问本机javascript和DOM,如果你选择使用它们。

In short we've built very complex sites (one of which was featured on the GWT blog) in GWT, and also using other libraries like JQuery. 简而言之,我们在GWT中构建了非常复杂的站点(其中一个在GWT博客上有特色),并且还使用了其他库,如JQuery。 I can tell you with 100% confidence that once you get your head around GWT it kills those other frameworks dead for complex tasks. 我完全可以告诉你,一旦你了解了GWT,它就会杀死那些因复杂任务而死的其他框架。 It also has some great built in things that help make things better, and even does some things that no other framework supports (like the magic it can do with images). 它还有一些很棒的内置功能,有助于使事情变得更好,甚至可以做一些其他框架不支持的东西(比如它可以用图像做的魔术)。 See this blog post for more details: 有关详细信息,请参阅此博客文章:

http://googlewebtoolkit.blogspot.com/2007/10/epo-builder-built-with-gwt.html http://googlewebtoolkit.blogspot.com/2007/10/epo-builder-built-with-gwt.html

Few things scare me like "generated Javascript". 很少有东西像“生成的Javascript”一样吓唬我。 The Law of Leaky Abstractions has got to be doubly true in these cases. 在这些情况下,“漏洞抽象法则”必须更加真实。

Writing effective cross-browser javascript is a tricky process of continuous refinement. 编写有效的跨浏览器javascript是一个持续改进的棘手过程。 Trying to decipher where some generated, obscured Javascript is going wrong is a major headache. 试图破译一些生成的,模糊的Javascript出错的地方是一个令人头疼的问题。 It's bad enough fixing bugs in the pure JS libraries. 修复纯JS库中的错误已经够糟糕了。

To me, GWT is a trick aimed at allowing backend developers to write front-end, in-browser code. 对我来说,GWT是一个旨在允许后端开发人员编写前端浏览器代码的技巧。 Unfortunately, the realities of modern web apps mean you just have to know Javascript and the DOM. 不幸的是,现代网络应用程序的现实意味着你只需要知道Javascript和DOM。 Something's going to break, and you're going to need to know why. 有些东西会破裂,你需要知道原因。

I think you're better off picking a good javascript library like jquery or prototype, and learning that well. 我认为你最好选择一个像jquery或原型这样的好的javascript库,并且学得很好。 Those libraries abstract away the sort of stuff that SHOULD be abstracted away and is unlikely to break in edge cases, like array operations and AJAX requests. 这些库抽象出那些应该被抽象掉的东西,并且不太可能在边缘情况下破解,比如数组操作和AJAX请求。

Yes, it does, since you'll be using Java and not Javascript. 是的,确实如此,因为你将使用Java而不是Javascript。

Superb IDEs, static code analysis, searching and refactoring - all this will make your life much easier on large projects. 卓越的IDE,静态代码分析,搜索和重构 - 所有这些都将使您在大型项目上的生活更加轻松。

No. It doesn't. 不,它没有。

It doesn't remove the complexity, it just makes it possible for you to deal with it from a Java Perspective. 它不会消除复杂性,它只是使您可以从Java Perspective处理它。 Since that gives you all the Tooling available from Java... that alone might make it worthwhile. 因为它为您提供了Java提供的所有工具......仅此一点就可以使它变得有价值。

JavaScript IDEs are getting better and better though, and typically if you're using a Framework like jQuery or Prototype, then you're probably going to find it easier than dealing with a heavy weight abstraction layer like GWT. JavaScript IDE越来越好了,通常如果你使用像jQuery或Prototype这样的框架,那么你可能会发现它比处理像GWT这样的重量级抽象层更容易。

My personal preference is to take the pure JavaScript approach, but that's because I like being able to work more closely to metal, and I'm disciplined enough to tame my JavaScript cats. 我个人的偏好是采用纯JavaScript方法,但那是因为我喜欢能够更接近金属工作,而且我有足够的纪律来驯服我的JavaScript猫。

With GWT, you're not actually writing JavaScript; 使用GWT,你实际上并没有编写JavaScript; it's entire value proposition is that you can write Java that it will compile down to JavaScript for you. 它的全部价值主张是你可以编写Java,它将为你编译成JavaScript。

I'm working on a project that has used GWT to pretty good effect. 我正在研究一个使用GWT效果非常好的项目。 It's a good choice for us since we're all primarily Java developers working on internal tools. 这对我们来说是一个不错的选择,因为我们都是主要从事内部工具的Java开发人员。 I can't speak to how useful it is for large end-user sites. 我不能说它对大型最终用户网站有多大用处。

One advantage I particularly appreciate is the seamless object serialization and deserialization. 我特别欣赏的一个优点是无缝对象序列化和反序列化。 Not only are the details of XML-RPC abstracted away, but since the same Java code is compiled to byte code for the server and javascript for the browser, you can code almost as if the server and client were running in separate class loaders in the same JVM. XML-RPC的细节不仅被抽象出来,而且由于相同的Java代码被编译为服务器的字节代码和浏览器的javascript,因此您可以编写代码,就好像服务器和客户端在单独的类加载器中运行一样相同的JVM。 For instance, you can construct a Java object on the server, send it to the browser as the return value from an RPC service call and the browser code can then use the identical Java class to manipulate the object you just returned. 例如,您可以在服务器上构造Java对象,将其作为RPC服务调用的返回值发送到浏览器,然后浏览器代码可以使用相同的Java类来操作刚刚返回的对象。 Likewise, parameters to RPC calls can be constructed as Java objects, with the server receiving an identical Java object on the other end. 同样,RPC调用的参数可以构造为Java对象,服务器在另一端接收相同的Java对象。 All this without mucking about in the details of (de)serialization. 所有这一切都没有在(de)序列化的细节。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM