lauantai 15. lokakuuta 2011

Dart programming: 99 Bottles of Beer

Dart is Google's new programming language, designed to replace JavaScript. Compared to JavaScript, Dart's main advantages are that it introduces classes and interfaces and removes primitive data types. In fact, typing is completely optional in Dart. Every variable is an object anyway, even those "int" and "bool" variables. In addition to those things Dart has a prettier and more modern syntax than JavaScript.

The downside is that as of writing this no browser natively supports Dart, not even Chrome. You can, however, try the language using the so-called Dartboard program at the Dart homepage. It is basically a Dart interpreter written with JavaScript. Note that currently it only works in Chrome and Firefox!

To test the new language I wrote the 99 Bottles of Beer song in Dart. The link will take you to Dartboard where you can try the program yourself. The program uses the neat one line syntax for getters, one setter (using which looks just like using a regular public variable!), a class with a constructor with one required and one optional parameter, a method with an optional parameter and also an exception is thrown when the wall runs out of bottles.

After writing this program and submitting it to The 99 Bottles of Beer Website I searched Twitter for other versions of the song in Dart and indeed found one from some Japanese blog. That version of the song is somewhat different to mine and nice too, but fails to follow the lyrics in the end.

So anyway, Dart looks nice and easy to learn. It looks like everything that JavaScript should have been in the first place. We'll see when Chrome gets support for it and whether other browsers decide to start supporting it as well. Unfortunately some people apparently tend to use old browser versions for ages, so Dart won't overtake JavaScript any time soon.

Ei kommentteja:

Lähetä kommentti