String say(String msg, [String from, String device = 'phone']) { ... }String say(String msg, String from?, String device? = 'phone') { ... }enableFlags({bool bold, bool hidden: true}) { ... }enableFlags({bool bold?, bool hidden? = true}) { ... }enableFlags({@required bool bold, @required bool hidden}) { ... }enableFlags({bool bold, bool hidden}) { ... }say(msg: String, from: String?, device: String = 'phone') -> String { ... }
enableFlags({bold: bool?, hidden: bool = true}) { ... } enableFlags(bold: true, hidden: false); enableFlags({"bold": true, "hidden": false});
enableFlags({bool bold, bool hidden}) { ... }var map: Map<{"bold": bool, "hidden": bool}> = {"bold": true, "hidden": false};enableFlags({bold: bool, hidden: bool}) { ... }
enableFlags(bold: true, hidden: false);var map: {bold: bool, hidden: bool} = (bold: true, hidden: true);Good examples. There are also inconsistent type names. For example, take String and bool, or List and int. If there is no primitive type in Dart, why some types are written in lower case and others in upper case. In Java, there is a reason for that. and why there are num and int both? Just to maintain compatibility with JS? I would also like that Dart 2.0 remove the ugly ternary expressions and pre-post increment operators. Nobody should write those unreadable stuff. Inconsistancy in a language itself is terrible thing. Go is much cleaner than Dart currently IMHO. Surely, we can hope that Dart 2.0 will have lesser ways of doing same things.
Not sure if I recall correctly, but I heard the optional/named parameter syntax is being reconsidered for Dart 2.0.I haven't see any proposals for that, let me do an informal proposal here:Postional optional parameters:Dart 1.0:String say(String msg, [String from, String device = 'phone']) { ... }
Dart 2.0:String say(String msg, String from?, String device? = 'phone') { ... }Named optional parameters:
Dart 1.0:enableFlags({bool bold, bool hidden: true}) { ... }Dart 2.0 :enableFlags({bool bold?, bool hidden? = true}) { ... }Named parameters:
Dart 1.0:
enableFlags({@required bool bold, @required bool hidden: true}) { ... }Dart 2.0 proposal:enableFlags({bool bold, bool hidden = true}) { ... }
This seems to me, as the most straight forward way.Types on the right/NNBD
With the proposed types on the right side, and non nullable by default, you may want to write it like this:
say(msg: String, from: String?, device: String = 'phone') -> String { ... }enableFlags({bold: bool?, hidden: bool = true}) { ... }
So now, it is more tricky, because a parameter can be optional and/or nullable. I would say that a parameter is optional if it either has a default parameter or if the type is nullable (or both).Syntax for named parametersNow there is one other thing. You may wonder, why do you propose the {...} syntax for named parameters in Dart 2.0? And why a colon `:` instead of the more natural `=` in the call? Well, there is a reason, I want to propose also the following. Named parameters are just sugar.enableFlags(bold: true, hidden: false);This would desugar to writing:enableFlags({"bold": true, "hidden": false});Yes, this is a map. Named parameters are sugar for writing a map. So actually, all parameters are positional now, where the last one can be a Map that can be written with some sugar as named parameters.So you may wonder, does this really matter anything? Who would write the later? Well, I think it actually does matter, because it helps making it much more natural to write javascript interop, because in javascript devs often add an option object (Map in Dart) as the last parameter. This object just serves as providing a bunch of named/optional parameters. With this proposal, this would map very straight forward to Dart.Can we generalize this?If you think about it, this kind of asks to give the Map object to have a more flexible type. Now with this proposal, here:enableFlags({bool bold, bool hidden}) { ... }
This says now, that the enableFlags function has as parameter a Map that must have two keys, the string bold and the string hidden, both of type bool. So if we can declare the type of the Map so specific here, why not in other Dart code?What about this syntax (assuming right hand types in Dart 2.0):var map: Map<{"bold": bool, "hidden": bool}> = {"bold": true, "hidden": false};
Well this syntax seems quite okay, I think we can provide a very natural sugar for this? Let's look a second at the syntax for named parameters:enableFlags({bold: bool, hidden: bool}) { ... }enableFlags(bold: true, hidden: false);
It seems clear to me that the sugar should look like;var map: {bold: bool, hidden: bool} = (bold: true, hidden: true);
Okay, so we have here a very specific kind of Map object, where all the keys are strings. Of course this is just a plain javascript object. And this should map to a plain javascript object when compiled. This would even give more advantages with javascript interop. For example, you could give much more auto completion and type safety to the react package.Thoughts?
--
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
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.
Not sure if I recall correctly, but I heard the optional/named parameter syntax is being reconsidered for Dart 2.0.
I haven't see any proposals for that, let me do an informal proposal here:Postional optional parameters:Dart 1.0:String say(String msg, [String from, String device = 'phone']) { ... }
Dart 2.0:String say(String msg, String from?, String device? = 'phone') { ... }Named optional parameters:
Dart 1.0:enableFlags({bool bold, bool hidden: true}) { ... }Dart 2.0 :enableFlags({bool bold?, bool hidden? = true}) { ... }Named parameters:
Dart 1.0:
enableFlags({@required bool bold, @required bool hidden: true}) { ... }Dart 2.0 proposal:enableFlags({bool bold, bool hidden = true}) { ... }
This seems to me, as the most straight forward way.
Types on the right/NNBDWith the proposed types on the right side, and non nullable by default, you may want to write it like this:
say(msg: String, from: String?, device: String = 'phone') -> String { ... }enableFlags({bold: bool?, hidden: bool = true}) { ... }
So now, it is more tricky, because a parameter can be optional and/or nullable. I would say that a parameter is optional if it either has a default parameter or if the type is nullable (or both).
Syntax for named parametersNow there is one other thing. You may wonder, why do you propose the {...} syntax for named parameters in Dart 2.0? And why a colon `:` instead of the more natural `=` in the call? Well, there is a reason, I want to propose also the following. Named parameters are just sugar.enableFlags(bold: true, hidden: false);This would desugar to writing:enableFlags({"bold": true, "hidden": false});Yes, this is a map. Named parameters are sugar for writing a map. So actually, all parameters are positional now, where the last one can be a Map that can be written with some sugar as named parameters.
foo(Map<String, bool> flags) {enableFlags(flags);}
So you may wonder, does this really matter anything? Who would write the later? Well, I think it actually does matter, because it helps making it much more natural to write javascript interop, because in javascript devs often add an option object (Map in Dart) as the last parameter. This object just serves as providing a bunch of named/optional parameters. With this proposal, this would map very straight forward to Dart.Can we generalize this?If you think about it, this kind of asks to give the Map object to have a more flexible type. Now with this proposal, here:enableFlags({bool bold, bool hidden}) { ... }
This says now, that the enableFlags function has as parameter a Map that must have two keys, the string bold and the string hidden, both of type bool. So if we can declare the type of the Map so specific here, why not in other Dart code?What about this syntax (assuming right hand types in Dart 2.0):var map: Map<{"bold": bool, "hidden": bool}> = {"bold": true, "hidden": false};
Well this syntax seems quite okay, I think we can provide a very natural sugar for this? Let's look a second at the syntax for named parameters:enableFlags({bold: bool, hidden: bool}) { ... }enableFlags(bold: true, hidden: false);
It seems clear to me that the sugar should look like;var map: {bold: bool, hidden: bool} = (bold: true, hidden: true);
Okay, so we have here a very specific kind of Map object, where all the keys are strings. Of course this is just a plain javascript object. And this should map to a plain javascript object when compiled. This would even give more advantages with javascript interop. For example, you could give much more auto completion and type safety to the react package.
For example, take String and bool, or List and int. If there is no primitive type in Dart, why some types are written in lower case and others in upper case.
I would also like that Dart 2.0 remove the ugly ternary expressions and pre-post increment operators. Nobody should write those unreadable stuff.
Go is much cleaner than Dart currently IMHO.
The QWERTY layout was designed to
prevent the jamming of mechanical
arms on early typewriters. The Dvorak
layout, by contrast, was designed to
maximize typing efficiency: it grouped
keys based on frequency of use, and
positioned keys to promote alternating
keystrokes between hands, among
other refinements. The result is a
30 percent improvement in typing
efficiency, and claim to most of
the world records for speed typing.
Despite the clear advantages of the
Dvorak design, QWERTY enjoys the
following of generations of people
trained on the layout, which in turn
drives manufacturers to continue
perpetuating the standard. Dvorak
wins on performance, but QWERTY
wins on preference.
This is the classic Performance vs Preference dilemma. It's nicely explained here (emphasis mine):
On Thu, Aug 18, 2016 at 7:43 AM, krupal shah <krupals...@gmail.com> wrote:For example, take String and bool, or List and int. If there is no primitive type in Dart, why some types are written in lower case and others in upper case.There is no internally consistent reason for the names of those types in Dart. In other words, if Dart was the only language you ever learned, those names would make no sense.You could almost say that lowercase names are for sealed types that users can't be implemented. Except that "String" is sealed and "num" is implemented by "int" and "double". You could also almost say that lowercase names are for fixed-size value types that can be safely stored inline. Except that "int" isn't fixed-size in Dart.The names are externally consistent in that they are cased similar to how corresponding types in some other languages are named. Both internal and external consistency help make your language easier to learn: they let users leverage things they already know. Balancing the two is tricky.Personally, I never liked the names. :-/
I would also like that Dart 2.0 remove the ugly ternary expressions and pre-post increment operators. Nobody should write those unreadable stuff.Supporting a feature doesn't mean users have to use it. There's a lot of value in having similar features to other languages even when you also have better alternatives. The former let new users be productive quickly even before they've fully learned the new language.
Does any other language have that sort of setup?