Friday, July 12, 2013

GWT for new project? No, thanks!


First of all, let me introduce myself briefly. I am a software engineer with more than 10 years java projects development experience. I am a software architect who pays attention to the common architecture NFQ stuff like dependency, code qualification, application maintenance, etc. And, last but not least, I am technology trend follower who sticks with the “moving” of modern software development.

Today I want to talk about GWT because I have done some researches while I am preparing a fresh new web application development. And I want to use this opportunity to give a new glass to some pure Java guy to let them know a little bit more about what is going on with JavaScript recently.

It is very interesting to read the discussion of using/ not using GWT:
  • Company behind the current GWT shows us a brilliant report and tells us “89% of respondents would use GWT on their next project”.

Today, almost one year later after Jochen Krause posted his blog, according to my personal research, I am afraid I have to agree with him and Guy Nirpaz.

Google has dumped GWT and GWT is dying.

I feel sorry to say that since the report from Vaadin has actually confirmed that GWT is a good choice for a new project. Well, the report is brilliant. But while I was reading it I could not stop asking myself why such a report should even exist. Ever see any similar report of JQuery, HTML5 or Hadoop recently? No? Why? Because it is not necessary! Such a report of GWT is trying to let the people calm down and remove the fear we have while considering using GWT on the next project. This is just my personal opinion, sorry about that.

GWT has left Google since 2012. Some people said it is good for GWT regarding the similar movement of Eclipse from IBM to open source community. But in my personal opinion they are not comparable. First, Eclipse is a platform while GWT is just a framework for web application. Second, after moving to the open source community, Eclipse is still heavily used in IBM. I don’t see the same thing happens in Google. Google has actually abandoned GWT and embraces pure JavaScript with HTML5 development and provided Angularjs and Polymer. The community is mad on Angularjs after they met it.

It was a great choice to choose GWT a few years ago while JavaScript was ugly and just toy language used for some fancy animation. Now JavaScript is mature enough for serious project development. It is in fact already used to build some amazing applications like Gmail, Blogger, Google+, etc. Let me show you why you should NOT use GWT for the new project anymore.

Google walks away and community is following

I haven’t seen any life signal of GWT for new project within the Google territory. People follow when Google walks away.

Enterprise application development environment

This is the most frequently talked reason for choosing GWT instead of an appropriate JavaScript framework like Angularjs. You will be benefit from mature development environment and java language itself. Well, that is correct. But recently JavaScript and its development environment become more and more mature:

            IDE – Webstorm
            Tools mamangement – NPM(Node Packaged Modules)
            Rapid development – Yeoman (Yo, Grunt, Bower)
            Build tool – grunt
            Dependency management – bower
            Unit test – Jasmin
            QA code analysis – jshint
            Test automationKarma
            Modular – RequireJS
            Framework - AngularJS
           
In some areas using JavaScript is even better than developing application in java. Consider what would be done if maven should be updated and what would be done if Yoeman should be updated? Much easier while using NPM right?

Object oriented programming

Many people have concern about JavaScript language itself. This is one reason why they consider using GWT. To be honest, just because JavaScript is a dynamic language does not mean it is not object oriented. You can find many JavaScript OOP tutorial, for example this one from MDN. There are many JavaScript designpatterns can be implemented in JavaScript, even beyond the GoF design patterns. Want to read some good books? Take a look at the post “Required JavaScript Reading”, Rey Bango did a really great work!

Short of JavaScript experience

GWT lets people work with java to build a web application running on the client side. Feel great right? But, look out! JavaScript code will be generated. We do not really get ride of JavaScript. We are end up with generated JavaScript code! It would be not true, if you think you don’t need to know JavaScript when GWT is used in your project. In fact, According to my personal experience, almost every GWT developer knows JavaScript. That makes me, as a software engineer, feel really bad. Why should you let GWT generate the JavaScript that you can write it on your own? In fact, the gap between Java and JavaScript is not as big as people image. It might take some time to understand some core dynamic language concepts like “closure” and “prototype inheritance”. The rest should be really easy for mature Java developer to understand. If you are confused at first glance, maybe you need to learn it three times.

The native language of web application is JavaScript. HTML is going to provide more and more API. People around the world are contributing great frameworks/libraries using JavaScript directly. It is difficult for GWT to follow these fast and flexible developments done by a more tremendous community. If you want to use them within GWT, you (or somebody else) have to make them available in the GWT way. Such a restriction makes me feel really bad. There is really no excuse anymore not to use JavaScript directly.


Framework

GWT is a mature framework which provides great features like MVP, data binding, etc. But now, thanks of AngularJS, you will have these features too while using JavaScript. And that is not enough, beyond these features, AngularJS provides some other excellent built-in features, e.g. dependency injection (like Guice does) and Directive which is the killer feature of AngularJS for customization and component integration.

Testability

Still think GWT is the only choice for building testable client side RIA? Now is the time to change your mind. You can test every thing by using AngluarJS, Jasmin, and Karma. For example: 


  1. it('should say hello', function() {
  2. var scopeMock = {};
  3. var cntl = new MyController(scopeMock);
  4.  
  5. // Assert that username is pre-filled
  6. expect(scopeMock.username).toEqual('World');
  7.  
  8. // Assert that we read new username and greet
  9. scopeMock.username = 'angular';
  10. scopeMock.sayHello();
  11. expect(scopeMock.greeting).toEqual('Hello angular!');
  12. });


Reference:

The usage of scopeMock via DI and the expect() method looks really familiar for us Java guys, right? :-) 

Widgets

Want to use some fancy widgets built by other guys? With GWT you have actually only one choice: GXT. Vaadin could be another one if the complete client-side API isavailable. With AngularJS the Directive feature make it possible and easy to integration any other JavaScript widget library. AngularJS co-creator Miško Hevery hasmentioned that AngularJS 2.0 will work with Polymer seamlessly. Is the trend now not clear enough to you?

Mobile app development

Hot topic. It looks like currently everybody wants a (web) mobile app. If you use GWT, you will have no other choice but mgwt teams up with gwt-phonegap. And the project gwt-phonegap shows us exactly the risk of using GWT for new project - You have no direct access to the generated JavaScript and it is painful for any extension and integration. Why I am saying that? Because PhoneGap provides its features only via JavaScript API and you are forced using gwt-phonegap to generate the appropriate JavaScript code, which can call phoneGap JavaScript API. This approach is painful. If you want to use a new xyz web technology built in JavaScript, you have to keep waiting until someone developed a gwt-xyz project or you must develop the gwt-xyz project on your own. Can you afford it? Some people might say you can use JSNI. Yes, you can! But please think about it, why use GWT if you want to call the JavaScript API directly? Using JSNI you will lose most benefits you have because your project is not a pure java application anymore.

If you have GWT project and consider build a mobile web app as a new client view, before you decide to use mgwt and gwt-phonegap, you should at least keep an eye on the development pulse of both projects:




Still don’t get it? Compare with the pulse of JQuery Mobile:


Have you seen the risk of using mgwt and gwt-phonegap in a serious project?

Please don’t get me wrong. Daniel Kurka did a great work. His work of the both projects makes a mobile app of GWT possible. He should get our full respect. But, business is business, you should think of your own benefit and risk.

Summary

If you currently want to develop a new client side RIA, still using GWT might not be the best choice, even if you have GWT project experience. For your long term benefit you should consider using JavaScript directly. If I were asked to build an enterprise RIA now, I would use the following architecture and technology stack:

  •  Architecture: SOFEA 
  • Server side: Java & Restful API (I am still a Java guy and Java is still the first choice for the backend of enterprise application.)
  • Client side: AngularJS, RequireJS, HTML5, JQuery Mobile for mobile web, Cordova for hybrid app, some other JS libraries depends on the concrete requirement.
  • Development Tools: maven or Gradle for backend Java project. NPM & Yoeman for frontend JavaScript project.
  • Test: Junit & mockito for Java project. Karma, Jasmine, and PhantomJS for JavaScript project.
  • CI: Jenkins

    Just my two cents, any feedback will be appreciated.
     

     

    15 comments:

    Avi Yafe said...

    Hi My name is Avi and i think you're probably right in all the things you have said.
    the only thing that you have missed is "strong types" which in large project still GWT has it advantages, refactoring of large project is something that you can't do easly.

    from guys how worked with java script the problem start with maintaining the project.

    NOTE:wirting new code is easier then reading (understanding) it!!!!

    The only thing that can help you with the point i mention is testing and testing agin and agian. which most of the programers realy hate!!!

    I think in few years when the JS projects will grow and the people who started them will leave them we see the real problems of using large JS projects.

    Avi

    Alain Ekambi said...

    You have so many things wrong in this post that I dont even where to start to answer you.
    Please do some research about GWT again...

    Lola Alfaro said...

    Alain, could you please expand? your comment is vague and completely unhelpful.

    Rico D'Amore said...

    Soooo..... I have to say as a Java developer I love GWT. That said I am much interested in Node and Angular together on the client. One thing that really helped me at our organization was phone-gap. Not for the access to the device, but simply for wrapping code into an ipa. (we have a strict ios need)

    We also write apps in .js is there another way to get an app on the iPad springboard other than phonegap?

    I'm not aware of one, but that doesn't mean anything really.

    great post, and yes Google dropping GWT has worried me for that past three years.

    talsi said...

    IMHO, Daniel's work is just much better (by-far) than jqm framework (especially performace-wise thanks to gwt). I preffer using this "small"(mgwt & gwt-phonegap) framework rather than using the jqm life-cycle-crazy framework, even if the learning curve might be a little bit steeper. Once you get past the "hello world" samples of angular and copy pasting from Jqm docs it gets really hard maintaing large scale project in JavaScript.

    Tirthankar said...

    100% true...develop an application with 50 developers out of which 20 developers are constantly new ones because of churn rate in the industry and maintain an enterprise application on web. You will know it what pain JS brings in maintenance. The code keeps growing and so many functions and features get written more than once to avoid regression and then clean up is out of question, because no one knows what is going to break.

    Then you start looking for tools which can do these..it goes on and on...Java script is a scripting language and for standing up a web page in a week with one or two developers project it sounds perfectly okay. For an enterprise application it is a NO NO

    Wendel said...

    Some comments.

    - Google most complex application has recently completely be rewritten in GWT. Google Apps Spreadsheet.

    - Gwt with a Java backend is must cheaper and easier to maintain than Angularjs with a Java rest backend.

    - Gwt business logic can be shared between the client and server.

    - Mgwt just released a new version. The library is complete. There is zero risk in using it even if they stop supporting it.

    - Gwt roadmap is very promising, with feature such as instant compile.

    - I have seen several Angularjs projects and they are slow, unreadable and for some reason the developers feel the need to write test units for every single bit.

    mark sasler said...
    This comment has been removed by the author.
    mark sasler said...

    There is an alternative tool similar to GWT called Dragome. But this one is about compiling bytecode to js, and it also has UI components support. Things like Incremental compiling, Java 8, HTML template are already supported. And there is no need to wait to ECMAScript 6 to be standardized because it already allows use of dynamic proxies continuation (js yield), classes, lambda (arrow functions).

    URL: www.dragome.com

    Emilio Bravo said...

    some clarification to what you mention in the post.

    " First, Eclipse is a platform while GWT is just a framework for web application." GWT is a SDK not web frameworks, There are many web frameworks built on GWT (GWTP, Errai, Vaadin, GXT, putnami ...).

    "I haven’t seen any life signal of GWT for new project within the Google territory. People follow when Google walks away.". False https://www.youtube.com/watch?v=-uJjh4DDW2s

    "Enterprise application development environment" You can use the same java tools for client and server development. If you are a full stack developer is more productive use one set of tools. Why not use javascipt at backend?

    "Object oriented programming", I guess we'll agree that java is much more powerful than javascript to place an object oriented programming.

    "if you think you don’t need to know JavaScript when GWT is used in your project" this is true.
    "According to my personal experience, almost every GWT developer knows JavaScript. That makes me, as a software engineer, feel really bad. Why should you let GWT generate the JavaScript that you can write it on your own?". javascript program that makes me feel insecure and I am more productive programming in java.

    "It is difficult for GWT to follow these fast and flexible developments done by a more tremendous community. If you want to use them within GWT, you (or somebody else) have to make them available in the GWT way" again false, JsInterop and Elemental 2.0, are being designed for safe integration with javascript and HTML5.

    Some advantages of GWT (if you have a java backend) over plain javascript obviated in the post:
    - type safe, for big projects this is pain killer.
    - Compiler optimization.
    - You can reuse java code between client and server.
    - Transparent logging integration (log4j or logback).
    - Java exceptions of client error.
    - jar for package.
    - Maven or gradle for complete construction of the project.

    Framework
    GWT is a SDK !!!!!!, You can even use angularjs framework on GWT :-D https://github.com/FinamTrade/angulargwt

    Testability
    You can use junit for testing cliente and server.

    Widgets
    You can use GWT widgets, Vaadin, GXT or HTML + CSS. We use Twitter Bootstrap + jquery.

    Summary:
    Architecture: SOFEA
    Server side: Java (Spring + JPA) & Restful API.
    Client side: GWT, twitter bootstrap, jquery and restygwt.
    Development Tools: eclipse, maven or Gradle.
    Test: Junit & mockito (gwtmockito).
    CI: Jenkins

    Joseph Gardi said...

    You said that you haven't seen any life signal in GWT. Well check out GWT.create 2015 and GWT 3.0. They're amazing!
    You asked why you should let GWT generate the javaScript. Here's the answer:
    -Optimize code: you'd be surprised at the amount of optimization it does. GWT is massively faster.
    -Add additional features to javaScript: in addition to javaScript GWT lets you do Java, and UiBinder.
    -Code Generators: Code generators let you specify what you want in an interface and then have the code generator generate the implementation at compile time. They let you do very powerful things:
    -Abstract stuff away
    -Abstract away browser differences by sending different code to different browsers. This is called permutations. This is much more efficient than jQuery's switch statements and allows GWT to optimize for each specific browser
    Bring Java code to the browser and reuse GWT code in JVM.

    Even js developers compile their code(google closure compiler).This is why so many people compile their code. There is an extraordinary amount of compilers to compile code to js. The other reason I don't write my own javaScript is that javaScript sucks. However if there is a js library I want to use I can use javaScript in GWT with JSNI. In fact, 62% of GWT projects use js.
    Your summary reveals the fundamental problem
    You said that you're only option for widgets is GXT but you have many options: mosaic, bootstrap, smart GWT, spiffy UI and much more

    Emilio Bravo said...

    More info about the future of GWT.

    GWT is at the core of new inbox's web client.

    Google is using GWT also in the new calendar and Sheets.

    http://gmailblog.blogspot.com.es/2014/11/going-under-hood-of-inbox.html
    http://www.infoq.com/news/2014/11/google-inbox-cross-platform
    https://news.ycombinator.com/item?id=8554339

    Why compile to js?, perhaps the following projects will help answer that question:
    - GWT
    - TypeScript
    - FlowScript
    - AtScript
    - CoffeScript
    - Dart
    - scriptsharp

    jonas brothers said...

    Its useless even those guys see that gwt is almost dead around the world they refuse to acept the fact let this crap die.

    Mohit Kumar said...

    It is strange when author claims that google doesn't use GWT, please do the research again and bit properly this time. I won't be exaggerating if I say google uses GWT "heavily".

    Andyarok said...

    The author seems to be a person with no knowledge of GWT, neither the time to spend learning it. We have used in more than one project it is really good provided the architecture is setup well to start with.