- Make "new" optional.
- Make "const" be an expression modifier, not a constructor call modifier, and inside the expression, all map and list literals are automatically const, and all constructor calls are also const invocations ("new" is not allowed, extra const prefixes are ok if you want them, so this is backwards compatible).
// Before:
var lst = const [const Point(1,1), const Point(2,2)];
// After:
// the const-ness applies to the contained objects.
var lst = const [Point(1,1), Point(2,2)];
// After shorthand:
// const applies to rhs
const lst = [Point(1,1), Point(2,2)];
UINode build() {
return new Container(
children: [
new Button(key: 'Go', content: new Text('Go'), level: 1),
new Button(key: 'Back', content: new Text('Back'), level: 3),
new Input()
// PopupMenu requires a PopupMenuController and should be wired up
// to a button to create the controller only when the menu is open, etc.
// new Container(
// style: _menuStyle,
// children: [
// new PopupMenu(
// controller: controller,
// items: [
// [new Text('People & options')],
// [new Text('New group conversation')],
// [new Text('Turn history off')],
// [new Text('Archive')],
// [new Text('Delete')],
// [new Text('Un-merge SMS')],
// [new Text('Help & feeback')],
// ],
// level: 4),
// ]
// )
// ]
);
}
}
Lasse made a couple of suggestions:- Make "new" optional.
- Make "const" be an expression modifier, not a constructor call modifier, and inside the expression, all map and list literals are automatically const, and all constructor calls are also const invocations ("new" is not allowed, extra const prefixes are ok if you want them, so this is backwards compatible).
My understanding is that with function generics 'new' could be optional.
(That said, making "new" optional is still a personal long-term goal :)
new List(); // normal way
List.new(); // metaclasses (if/when gilads DEP will be accepted)
List(); // optional new keyword
--
You received this message because you are subscribed to the Google Groups "Dart Core Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to core-dev+u...@dartlang.org.
While i see the benefit in metaclasses, i am not sure what would be gained by making new optional, other than typing four less characters.
Why would you like ìt to be optional?
It could also remove the need for non-const factory constructors completely. There is no real difference between a non-const factory constructor and a static method, except that the former needs to be called using "new" and have the surrounding class as return type.
On Thursday, April 9, 2015 at 10:21:52 PM UTC+2, Benjamin Strauß wrote:
(That said, making "new" optional is still a personal long-term goal :)
[..][..]
Another, related, wish: A const constructor can't create a new const object containing an argument. If you write: `const Foo(a) : x = const Bar(a);` then it's invalid because it can't be run with "new" because `a` isn't constant. If you write `const Foo(a): x = new Bar(a);` then it's invalid in a const context. Now, if you could write: `const Foo(a) : x = Bar(a);` and have the omitted const/new" be treated as "const' in a const context and as "new" in a runtime context, then it becomes much more useful. Omitting const/new actually gives extra power!
On Thursday, April 9, 2015 at 10:21:52 PM UTC+2, Benjamin Strauß wrote:(That said, making "new" optional is still a personal long-term goal :)As a new developer learning dart, i would be slightly confused why there are three different ways to create an object.
new List(); // normal way
List.new(); // metaclasses (if/when gilads DEP will be accepted)
List(); // optional new keywordWhile i see the benefit in metaclasses, i am not sure what would be gained by making new optional, other than typing four less characters.
var listClass = List;listClass();
Why would you like ìt to be optional?I don't want it to be optional, I want it to be removed completely - I just don't think that's likely to succeed, so the compromise is to make it optional, which will be a backwards compatible change.Making new optional is not only about not typing four characters - but that does add into it too.The four characters are redundant. It's statically detectable that I'm calling a constructor, and not having a "new" in front is known to be an error. Writing redundant and unnecessary stuff is just annoying, and getting rid of the annoyance is an improvement in itself.It could also remove the need for non-const factory constructors completely. There is no real difference between a non-const factory constructor and a static method, except that the former needs to be called using "new" and have the surrounding class as return type.It has been argued that having constructors be different from static functions makes it easier for the user to see what is going on. You can *see* that you are creating a new object.That's just not true. We have factory constructors that don't create new objects, and we have static methods that do create new objects.It does help with naming, though - if you write `new List.fixed(...)` you don't need the constructor to have a name that says that it creates something. A static function would probably have been named `List.createFixed(...)`. I think that's only a matter of tradition, and we can still use `List.fixed(...)` as a constructor without getting confused - it works for Scala.So, we have some classes with static factory methods (Uri.parse(...)) and factory constructors (Uri(...)) where the latter require "new" and the former does not. For `Uri`, that was a choice, and I think the right one, but it's not without problems - it's not easy for a user to see which members are constructors and which are static methods. If you could call them in the same way, then the suer doesn't have to know - the static class API is indifferent to what is a constructor and what is not.Some classes have static factory methods that are asynchronous. You can't make these factory constructors because constructors must return the correct type - which is not a Future.This means that some APIs will have both normal constructors and async factory methods, and you get users who want to write `new Foo.asyncFactory(...)` because they want "new" whenever they are creating a new object. If we remove "new", then hopefully that goes away, and an async factory method won't stand out as much.We still need to have generative constructors, and be able to distinguish them from other members, due to the generative constructor chaining of subclasses - you can't do `Foo() : super.bar();` if super's *bar* isn't a *generative* constructor, but factory constructors become much less interesting.Another, related, wish: A const constructor can't create a new const object containing an argument. If you write: `const Foo(a) : x = const Bar(a);` then it's invalid because it can't be run with "new" because `a` isn't constant. If you write `const Foo(a): x = new Bar(a);` then it's invalid in a const context. Now, if you could write: `const Foo(a) : x = Bar(a);` and have the omitted const/new" be treated as "const' in a const context and as "new" in a runtime context, then it becomes much more useful. Omitting const/new actually gives extra power!