Some thoughts about Google’s new Dart programming language

Ever since it was announced that Dart would be announced at GOTO conference I’ve been wonder what dart would be like. I thought I’d take the time put down my initial thoughts here.

Is there a need for another language?

Tim Anderson poses the question nicely here, so I thought I’d have a stab at answering it. There are a lot of programming languages in the world, so there would seem to be limited space for a new one. However, I think Google are creating this language for two reasons:

1) they want improve the web by replacing JavaScript with something more sensible.

2) they want to get themselves and others off Java.

Those are two fairly bold statements, so I’ll try and justifier them, taking each in turn.

The first one is fairly easy to justify from the point of view this is Google’s motive for creating the language as we have the leaked memo. But it’s probably worth talking about whether replacing JavaScript is a good thing. I’m not a huge JavaScript fan, I do think JavaScript has showed itself to flexible enough to be extended in interesting ways by library writers, but ultimate that is enough for a language that has some huge glaring floors. So, yes a JavaScript replacement is a good thing in my opinion. However, there’s also the question of how feasible this is. At the moment Dart relies on being crossed compiled to JavaScript, which isn’t a hugely original idea. It’s true that Dart also runs well on a server, and this is enough to let Google claim Developers have not been able to create homogeneous systems that encompass both client and server, except for a few cases such as Node.js and Google Web Toolkit (GWT). I think that statement is completely untrue. There are many systems, including, but not limited to, WebSharper (my personal favorite), ScriptSharp, HappStack (thanks to BlazeHtml), that let developer's create systems in a homogeneous way. All use a cross compiling another language to JavaScript, the same approach that Dart will take at least initially. The big benefit of Dart would be if Google get Dart adopted by all browser venders as a language that executes in the browser. As they already control one browser it’s fairly certain it’ll be making it’s way into that soon, but the real question is will other vendors follow suite. As Dart is open source, theoretically it wouldn’t pose too much of a problem for open source browser like Firefox to integrate it, although who knows how Mozilla will feel about Google trying to push them around. And I think one can safely assume it won’t be at the top of the IE teams todo list. So, although a JavaScript replacement is needed, in my opinion at least, its doubtful that Dart will offer anything better than what’s already available, at least not for a very long time filled with Google lobbying the other browser vendors. Also if Dart is to replace JavaScript it might have been nice to aim a little higher and replace it with something better (see my thoughts on this in the section: What is Dart like as a language?).

To try and justify the second statement: it’s fairly well document that Google uses a lot of Java internally. It’s also fairly well document that Google are having a big spat with Oracle, the new owners of Java. So it’s not a great leap of imagination to think that Google would be interested in moving away from Java. Problem is where would they go? Clearly C# is out, as Google detest Microsoft as least as much as they do Oracle. So while there is lots of other languages out there they could use, there’s nothing out there that really leaps as the Java replacement (at least if you don’t want to go with C#). So my guess is that Google hope to sweep up programmers who are unhappy with both Microsoft and Google as well as get themselves off Java.

What is Dart like as a language?

Well for me it’s a disappointment. I guess the biggest disappointment is that the basic unit of code is a statement, rather than expression, meaning it is an imperative rather than a functional language. This is a fundamental design choice that can be altered, the rest of the remarks I’m going to make probably could be fixed in one way or another but this can’t be. So why might it have been a good idea to make the language expression orientated rather then statement orientated? Well much of the progress in modern object orientated programming has been inspired by functional programming, here I’m think of Linq and jquery as the prime examples but there are probably others. While these frameworks work well, they are somewhat limited by being built on top of statement orientated languages. For example one of the criticisms of Linq I hear most often is that Linq queries often end up being monolithic blocks that are difficult to pull apart and once they get bigger than, say, five lines, they become very difficult to understand. I’d contrast this to F# pipeline expressions, basically the equivalent, but in an expression ordinated language, which are easy to understand and to pull apart and refactor.

Apart from being imperative, Dart also seems very conservative, lacking useful features. This is not that surprising for a first cut of the language, but all the same, there’s nothing that leaps our and says use me for your next project. The things that I’d like to see that are missing are (and admittedly I haven’t spend as much time as I’d like looking at the language as I’d like so I could be wrong on any of these points):

- Tuples and currying. These greatly improve compositionality in a language, although it is good to see there are functions as first class values

- No immutability. And unless I missed it way to declare a value as being read-only, let alone nice a nice easy way to create a modified copy of a value.

- No pattern matching. Just makes so many difficult problems easy, hard to see why you wouldn’t put it into a language.

One good choice I think they made is that all concurrency must use actor model type mechanism called isolates. However, I do have one small quibble with this. With no immutability in the language how will they archive this isolation? Surely the actor will leak references all over the place. I could be wrong, but I strongly suspect this has been fixed with lots of fairy dust.

Google have said they are hoping for “rapid evolution” of Dart so it will be interesting to see what features do get added.

What is Dart made of?

As Dart is open source I thought it might be nice to peak under the covers and take a look at what dart is made up of. Once past the fairly broke process of installing depot_tools, so I could check out all the sources, it was fairly easy to do this using, yes you guessed it, an F# script. But before we dig into the numbers it’s probably best take a look at the top level of the source tree (only give a comment where it doesn’t seem obvious what the directory is for):

- client – a set of development tools for Dart
- compiler
- corelib – the core library for Dart
- editor – (presumably, as there’s no read me) an editor for Dart
- language – a parse based on antlrworks
- runtime 
- samples
- tests
- third_party
- tools – not sure what this is about, seems to have some build stuff and syntax highlighting for vim

The file type counts are:

Extension Count Percent
.dart 3053 16.989427
.py 2993 16.655537
.java 2791 15.531441
.js 1059 5.893155
.html 1007 5.603784
.pm 895 4.980523
.gif 585 3.255426
.h 564 3.138564
.pl 543 3.021703
  472 2.626600
.cc 469 2.609905
.txt 359 1.997774

 

If we exclude the third_part directory:

Extension Count Percent
.dart 3053 46.145707
.java 1756 26.541717
.gif 483 7.300484
.cc 193 2.917170
.png 143 2.161427
.h 110 1.662636
.tlog 99 1.496372
.properties 79 1.194075
.py 78 1.178960
.obj 43 0.649940
.xml 41 0.619710

 

So we can see Dart is overwhelmingly written in Dart. Notable exceptions to this are the runtime directory which seems to be all C or C++ and compiler and editor which are java. The compiler readme file does contain a vague hint that it’s just a '”placeholder”, so presumably it’ll be bootstrapped at some point. It’s also worth noting that that third-party dir does seem to contain some stuff which isn’t actually used, for example I can see, closure_compiler_src but no evidence of Clusure being used.

Conclusion

Dart isn’t a language that leaps out at me and says use me for your next project, and that’s the key disappointment for me. However, politically, and by that I mean coming  from Google and aiming to replace JavaScript, I think it’s in an interesting position, so  for that reason I’ll be following the project.

Bookmark
dotnetkicks+, digg+, reddit+, del.icio.us+, dzone+, facebook+

Print | posted @ Wednesday, October 12, 2011 10:51 PM

Comments on this entry:

Gravatar # re: Some thoughts about Google’s new Dart programming language
by Art Scott at 10/13/2011 4:29 AM

Thanks Robert.
Knowledgeable and perspicacious.

Your comment:

(Note: all comments are moderated so it may take sometime to appear)

Title:
Name:
Email:
Website:
 
Italic Underline Blockquote Hyperlink
 
 
Please add 6 and 6 and type the answer here: