A look at Dart from the eyes of an OO programmer
The Web Dev Zone is brought to you in partnership with Mendix. Discover how IT departments looking for ways to keep up with demand for business apps has caused a new breed of developers to surface - the Rapid Application Developer.
The features... mostly Good Things(TM)
- a main() method which is executed at startup.
- Real classes and almost everything useful that Java does.
- Scala-like features, such as variables declared with mandatory var or final (val in scala) and Scala constructors.
Dart is not statically typed, although there are optional type hints like in PHP's case.
Some (understatement) of its features are taken from Java, one of Google's standard languages: for example, interfaces for collections are borrowed from the Java Collections Framework. But why invent yet another terminology?
I can't remember seeing some ideas of Dart in any other language. Some are puzzling, while some are worth a second look.
A Factory class for each interface creates objects of a default class. Even int and double are just interfaces. This is indeed innovative, but it's early to say if it's actually useful.
Type checking implemented only for documentation and warning. PHP's type hints are the most similar concept I know: but they are checked at runtime and produce serious errors. Dart's type annotations instead produce compiler warnings, and are oriented also to documentation. This will avoid Java-esque complaints and boilerplate code auto generated just to make the compiler happy.
A checked mode is available for development, that works like PHP type hints and forces types to be respected.
Each page has a standard entry point: main() triggered by the DOMContentLoaded event.
- a simplified DOM Api, which does not take into account XML support.
- query() and queryAll() methods for CSS-based selectors, borrowed from jQuery.
- DOM collection types are the language ones: lists, maps and sets. So a single Api can access both a map and and element's attributes.
- Definition of event listeners directly on DOM elements (element.on property). There are also add()/remove() primitives to avoid overwriting listeners.
- Flash, Java, Google
Dart's types shouldn't even be called types, since they're thrown away in compilation.
It's neither a static nor a dynamic language. But this article has been called FUD on Hacker News.
In fact, if Microsoft built Dart we would be out with torches and pitchforks. Well, they did create SilverLight, one of the most hated languages at least here in Italy; you cannot watch the national television on Linux because it's served via SilverLight. They did it with VBScript, already compared to Dart. It's a little better than Flash, since it probably can't not eat into battery life as much.