David Chandler's Journal of Java Web and Mobile Development

  • David M. Chandler

    Web app developer since 1994 and Google Cloud Platform Instructor now residing in Colorado. Besides tech, I enjoy landscape photography and share my work at ColoradoPhoto.gallery.

  • Subscribe

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 223 other followers

  • Sleepless Nights…

    October 2011
    S M T W T F S
  • Blog Stats

    • 1,033,665 hits

First thoughts on Dart from a GWT developer

Posted by David Chandler on October 10, 2011

I consider myself more of a tools & frameworks guy than a language geek so I’m more likely to groan than gush over a new language for the Web.

However, as I dug into Dart a bit working on a couple of the samples, I have to say I caught a bit of the same fire that I felt when I first encountered Google App Engine and GWT. Dart is fun. Coming from a GWT / Java background, I found it easy to get started.

Here are a few of my favorite things about Dart so far:

  1. Closures. You can register an event handler as simply as
    element.on.click.add((Event e) { window.alert('You clicked'); });
    Already, I don’t miss the clutter of anonymous inner classes.
  2. Functions can be passed by reference. You can define
    myClickHandler(Event e) { ... }
    and then just write
  3. Function type aliases are a compact way to create your own callback types.
  4. Optional typing. At first I thought I wouldn’t like this. However, as the Ruby community has long pointed out, Java is full of redundancy. Why write
    String[] values = new String[] {"a","b","c"};
    values = ['a','b','c'];

    will do?
  5. Getters and setters. If you define methods using the get or set keywords, Dart will invoke them when you reference a field using dot notation. That is, some.property automatically invokes some.getProperty();.
  6. Constructor initializers. If an argument has this. before it in a constructor argument list, the field with that name will automatically be initialized with that argument’s value. So a constructor that simply assigns arguments to fields can be written on one line:
    Point(this.x, this.y);
  7. The Dart DOM and HTML libraries provide convenient and mostly transparent access to the DOM. Thus, you can easily use static layout in an HTML file and call document.getElementById(). The Canvas code in the Sunflower and Spirodraw samples is almost identical to the corresponding Javascript.
  8. document.query(id_or_class) and .queryAll() work very similar to jQuery. These are part of the Dart HTML library, which offers convenient access to the DOM.

Thanks to all the syntactic sugar, Dart code is quite a bit smaller than the corresponding GWT app. My GWT sunflower app required very little modification to run in Dart, and the Dart code for the app went from 96 lines to 58 lines. Better still, I replaced the GWT SliderBar widget (almost 1000 lines of Java) with just a few lines of static HTML (my apologies to Firefox users: FF doesn’t support <input type=”range”> yet). Spirodraw was reduced from ~500 lines to ~300 lines, and the control panel layout is completely static HTML, which makes it easier to read.

Of course, it’s very, very early for Dart. GWT is a mature toolkit with a solid IDE (Google Plugin for Eclipse, among others), mature frameworks for RPC, MVP, etc., and a large open source community. But based on first looks, Dart is a promising new way to write Web apps. If browser vendors implement the Dart VM natively, it will rock! Chrome seems pretty likely to do this, at least. Until then, you can use dartc to produce JS for any modern browser. Hopefully, the editor (demo’d in the GOTO conf keynote this morning) will ship soon and make it easy for everyone to get started with Dart.

See also

9 Responses to “First thoughts on Dart from a GWT developer”

  1. How do you see the future with dart and gwt?
    Does this mean that google is gonna put all the eggs in Dart?
    Can this be the start of an end for gwt?
    thanks for the posts.

    • Hi Raymond, it’s much too early to discern what may happen. Google uses GWT in over a thousand projects internally, whereas Dart is brand new. Google continues to invest in GWT and will continue to support it for a long time to come because it is used so widely within the company. So no, Google is certainly not putting all its eggs in the Dart basket. Whether it’s the beginning of the end for GWT is a bit like asking if any given day on the stock market is the beginning of a new bull or bear market. It depends greatly on how the Web programming community receives Dart.

  2. Seems like a nice new language.
    But I share your opinion that it will take some time to become as mature as GWT is today.
    Personally I hope GWT will not vanish but integrate Dart! πŸ˜‰

  3. When I saw the samples for Dart I knew you had a hand in writing some of them πŸ™‚

  4. ARMistice said

    Thanks David,

    for the great Demos, and your view on Dart. Do you know where I can find an API for the dart:dom library? Or something similiar?

  5. Hugh said

    97 % of your favorite things about Dart already apply to JavaScript + HTML + CSS.

    • Why yes, some of my favorite things about Dart are also some of my favorite things about Javascript. That’s why I like Dart–it allows me to use some of those features without having to hold my nose at the lack of explicit typing and accompanying lack of tool support.

  6. Google’s an extremely large company with many different moving parts. It’s unlikely that they’ll put all their baskets in any one thing (meaning GWT I don’t think would be abandoned anytime soon)

    Glad to see Dart though. It looks like what I’ve been hoping for over the past few years: a fluid, easy to work with language with a fair amount of type safety and static-language-benefits like compile time errors, good tooling (like code-complete), etc…

    Thanks for the summary

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: