Smart Tech for a better Web
How did Mr Google proceed?
He thought it would be good to combine the best of both worlds. And he even looked at some other worlds too. First he introduced classes again. And there is a main() method again. And interfaces. And Types. But the latter one is only optional, if you would like to keep your flexibility.
There is a command line which is already very useful. With Dart you can create server side code, that’s pretty nice.
You have to compile Dart yourself. This is fine with Linux and easy with OS X but it is a bit complicated on Windows systems. So you can’t say it is widely available.
Anyway, Dart is not for production yet.
This is how Dart looks:
I have made up a class with a member called „value“. Followed by two constructors. The first one is very easy to explain, it is pretty much like the default constructor in Java. The second one is different: it is a named constructor. These act like every constructor, just with a name. If you would like to call it, you need to call:
This is because in dynamically typed languages it is not really easy to add a feature as „overloading“. If you look at the constructor signature, it is a bit weird:
No brackets. It means that you assign the first parameter to the member field „value“ automatically. This is very nice and actually you’ll find things like this in other aspects of the language too. This does not prevent you to do something like:
Of course you can make it look like Java too:
Google devs say you can use types for documentation.
In addition they give you a type checker tool which finds issues for you and generates warnings. It is more a „Lint“ tool and you should not mistake it with what you get on the Eclipse problems view. You need to enable it manually to make it work.
On the commandline it is:
This generates warnings in the following code:
Finally in Dart:
Here is another selector example:
It selects elements with these two classes. Dart also has streamlined the way you can get attributes from a specific element.
There is the factory pattern build into the language. I have already read „Design Patterns are so outdated“. I cannot agree. Design Patterns still are a useful way to communicate between developers. The Factory pattern is a very important one and widely used. If you don’t want it, you are not forced to use it. But looking at it, it is really smart and nice.
There are already very good a clean APIs for the most important work (like Collections). There are Exceptions and there are Generics. One might say, why do you need Generics when you have such a weak typing system? Again: it is about readability and of course you have the type checker doing some work for you – before you go into production.
Isolates are there. This is powerful and I expect that there will be a chance to create multi-threaded apps with Dart in a while.