Actually I think Dart has a lot of benefits in terms of syntax compared to Java. I am working with java since 2001, so I can tell. If you are interested to briefly look at it, you can do that here: https://www.dartlang.org/docs/synonyms/
Well, comparing with Java is aiming a bit low, isn't it?
Compare Dart's "shorter alternative" of a bog-standard class ...
// Shorter alternative
class Person {
String name;
// parameters prefixed by 'this.' will assign to
// instance variables automatically
Person(this.name);
}
Let's remove the comments for a more visually fair comparison:
class Person {
String name;
Person(this.name);
}
vs
class Person(val name: String)
Ok, you save a line. I don't think that's a big deal. Also, the Dart version is very clear about what's a field or not. The first example I found of Scala classes on their site is this:
class Point(xc: Int, yc: Int) {
var x: Int = xc
var y: Int = yc
def move(dx: Int, dy: Int) {
x = x + dx
y = y + dy
}
override def toString(): String = "(" + x + ", " + y + ")";
}
With text that says `x` and `y` are the fields. What about `xc` and `yc`, I thought those were the fields?
Another thing I like about Dart is that the possible variations on the constructors fall into place, consistently:
No constructor args:
class Person {
String name;
}
Optional constructor args:
class Person {
String name;
Person({this.name});
}
Super call:
class Person extends Animal {
String name;
Person(this.name) : super() ;
}
The short Scala form may do that as well for all I know,
> Let's remove the comments for a more visually fair comparison:
It was not meant to be unfair, I just took an existing example. If the Dart devs thought they needed the comments to make it clear what happens, then it's a decision I respect.
> Ok, you save a line.
Three.
> With text that says `x` and `y` are the fields. What about `xc` and `yc`, I thought those were the fields?
For standard classes, the compiler just does what you tell him:
If you write that you want a "val", you get an instance value, if you write a "var", you get an instance variable, if you write nothing (like in this case), you will usually get ... nothing.
That's perfectly clear in my book.
> Another thing I like about Dart is that the possible variations on the constructors fall into place, consistently:
In most languages, allowing a constructor which forgets to initialize things is considered a compiler/language bug.
(And having more than one constructor is pretty much considered to be an anti-pattern in Scala anyway.)
Yes. It's probably the same weird confusion I had, too ... because all "experts on the Internet" complain about Scala being a kitchen-sink of features, but if you actually walk into it, you just wonder how they managed to reduce and condense features into such a small, well-designed orthogonal core ... and wonder why no one else did it before.
In hindsight, Scala is much smaller than C#, F#, C++, OCaml, etc. while still being more expressive and comfortable to use.
Dart makes me excited, when i am honest :-)