Hacker News new | past | comments | ask | show | jobs | submit login

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/

Dart makes me excited, when i am honest :-)




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);
  }
... with something more modern:

  class Person(val name: String) // Done.


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.)

> Super call:

In Scala:

  class Person(val name: String) extends Animal


Maybe I am old-fashioned, but declaration of member variables in like in the second example makes me afraid. :-) Whats that for a language btw?


Scala.

C# 6 also copied it (although it doesn't really look that clean, because of their incompatible mess in fields vs. methods vs. properties).


Scala did never grew in me. But I heard its getting better once you made the first few weeks.


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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: