class Person (name, age) {variable String name;variable Integer | String age;shared String toString => "Name ``name``, Age ``age``";}Person person1 = Person ("Cristian", 26);Person person2 = Person ("Mike", "Twenty three");print (person1.toString);print (person2.toString);
class Person (this.name, this.age) {String name;Integer | String age;String toString () => "Name $name, Age $age";}var person1 = Person ("Cristian", 26);var person2 = Person ("Mike", "Twenty three");print (person1);print (person2);
Now we would only need inner classes and first class modules being top level classes and we would be a bit closer to Newspeak. ;)
At this point i would take the risk. I think the userbase is still small enough (no offense) to take such breaking changes.
Otherwise all your code needs to deal with it possibly being a string or int
Anders, I just wanted to use a union type in Ceylon and "got creative" ;)
A bit tangential but I reckon having age as a union type on the property is a bad idea. OK on the constructor arg but from there I'd always store it as an int in the property.
Otherwise all your code needs to deal with it possibly being a string or int
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.
I think removing new makes more sense when it is mandatory and not optional. Otherwise we will see a mix of code that uses new and some that doesn't use new. And it is too late to remove the new keyword completely.
Not sure how I feel about primary constructors. When thinking about the case of multiple constructors they don't feel quite so elegant.
Totally removing new is too much, it would make current code useless. The code proposed here contains no breaking changes.
Primary constructors are like a default constructor but every other (named) constructor needs to call the primary constructor because its inputs can be used to initialize final variables (I didn't de a good job showing this).
class SkyHome extends App {Widget build() {return new Theme(data: new ThemeData(brightness: ThemeBrightness.light,primarySwatch: colors.Teal),child: new Title(title: 'Sky Demos',child: new Scaffold(toolbar: new ToolBar(center: new Text('Sky Demos')),body: new Material(type: MaterialType.canvas,child: new DemoList()))));}}
So many language features in one email thread! :)For now, I'll just talk about getting rid of new. We've talked a lot about union types before and there's another thread about it going on. Primary constructors are interesting too, but personally I don't find them super compelling.First of all, there's no technical reason that Dart has a new keyword that I know of. Removing it would not cause ambiguities, and it does not have any real semantics that cannot be expressed some other way.
--
Why not have both styles?
new Object();
Object();
Then new becomes optional and the Java teams using Dart can continue using new for the sake of familiarity and at the same time you don't break older libraries using new.
There are now and have always been people on the team who'd like to do away with new. I'm in the camp. My opinion was strengthened when I started looking at the example code from the Sky project:class SkyHome extends App {Widget build() {return new Theme(data: new ThemeData(brightness: ThemeBrightness.light,primarySwatch: colors.Teal),child: new Title(title: 'Sky Demos',child: new Scaffold(toolbar: new ToolBar(center: new Text('Sky Demos')),body: new Material(type: MaterialType.canvas,child: new DemoList()))));}}With React-style rendering frameworks, a lot of code is constructing new lightweight objects. In code like the above, the new really does stand out as a pointless, heavy tax. It would read more like a DSL without them.