State of the Dart

Coding again at last! In Dart. Herewith are my initial experiences with Dart.

The reason I am using Dart is to run in the browser, which is the best platform for modern UI work. Being able to run on every device in the galaxy is a secondary benefit. What Dart offers over JavaScript is a serious language and a professional development environment. Everything I need is there, albeit still immature.

I spent an hour or two reading the “Up and Running” guide and was able to start coding immediately. The major differences in Dart from vanilla OO ala Java are optional typing and constructors. Much has already been written about the optional typing but so far I haven’t found it to be a big deal compared to simple “var” type inference. It lets you get away with things like heterogeneous arguments and duck typing but so far I haven’t needed those features. Dart’s new approach to constructors aren’t discussed as much but are a big win for me.

Dart makes object construction atomic and deterministic. Some common initialization idioms are outlawed – for example initializers can’t reference ‘this’. But it is so great not to have to deal with revealing partially constructed instances or non-deterministic class initialization order. A related feature is compile-time constant object instances with interning. There is also nice support for factory constructors. Dart’s creators are VM experts, and I think it shows in the way they have rationalized the insanity of laissez-faire construction.

The Dart Editor is a slimmed-down Eclipse with all the essentials: type-driven completion, autofix suggestions, type and doc lookup, usage-definition traversal, and refactoring. Some of it is rudimentary, but I find there is enough to get real work done without cursing. I am a little worried that analysis time is already perceivable with less than a thousand lines of code. Update: there do seem to be scaling problems in the static analyzer, but I am told they are being actively worked on. I am hoping they can fix it before I write too much code, or else IntelliJ gets their plugin working.

The libraries are the most immature, and feel a bit like an afterthought. There are excellent highly evolved class libraries to copy from, but it feels like they started from scratch. Or started from JavaScript, which is about the same thing. For example they just added Object.hashCode, and there still isn’t a Collection.equals method. But compared to JavaScript, the Dart libraries are already a giant win. I suppose they are prioritizing breadth over depth, which makes sense. So far no show-stoppers, but there is still an alarming amount of churn in the APIs.

The one feature I wish Dart had was case classes as in Scala. These give you immutable value objects without the boilerplate hashcode and equals, and give you type-driven switch statements.

Anybody else have experiences with Dart to share?

12 Replies to “State of the Dart”

  1. Now I wish I had spent some time with Dart. I have been putting off trying it out till other brave souls had some experience with it. And also there are only so many hours in the day for all the things I would like to try out!

    Really appreciate this kind of description of your experiences too. Looking forward to reading more about the nuts-and-bolts of the work you are doing. Peace.

  2. I’m going to do what I’m not supposed to do and say I like Coffeescript on NodeJS.
    For example if you wish to double every even number in a list in Coffeescript.
    double_odds xs = [x*2 | x <- xs, x `mod` 2 == 0]

    If I was going to program in Haskell I would use FayLanguage to compile to Javascript https://github.com/faylang/fay/wiki

  3. Sorry I was asleep when I wrote the code, that was Haskell, this is coffeescript to double odd numbers

    double_odds = (xs) ->
    x*2 for x in xs when x % 2 is 0

  4. Thanks for the write-up!

    If you’re curious, here’s one way to double all even numbers in a list, in Dart:


    main() {
    var nums = [0, 1, 2, 3, 4, 5, 6];
    Iterable doubled = nums.where((x) => x % 2 == 0).map((x) => x * 2);
    print(doubled.toList());
    }

    1. TypeScript has a better IDE experience, and patches some of the problems with JavaScript, but not all of them, and it still leaves you with the chaos of JavaScript libraries. For example, I need a TreeMap. After much searching I could only find a single quality implementation, inside the Chrome V8 test suite (which is the basis of the Dart implementation). I don’t have time to become an expert JavaScript Librarian/Archaeologist. I want a complete quality library that just works out of the box.

      1. Interesting. So TypeScript relies on/provide interop with the existing ecosystem, this is its strength and maybe a weakness also because that ecosystem is not very strong.

        I guess Google really has a shot then. I mean, building an ecosystem is hard, but if they do it right they could turn that around into an advantage.

  5. I have to say I’m getting very excited about Elm-Lang ( http://elm-lang.org/ ).

    I’ve never quite had the motivation to get into Haskell before. But a simplified / cut-down Haskell, that compiles to the browser and has FRP baked in feels like the motivation I need.

Comments are closed.