Foo foo *;Bar bar *(foo);
Foo foo = new ();
List<Point> p = [new (0,0), new (10,10)];
Not every declaration uses constructors.
What about:
final otherList = someList.map...??
--
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 the reason why `var x = new XType(some, argument, s);` does not work sufficiently well is that it violates the language semantics to infer the type
(it's ok for an editor to offer completion based on an optimistic assumption that a given approach to inference produces a "correct" result, but it is not ok to throw a type error in checked mode if the programmer violates a typing constraint that the compiler invented).That's the reason why I've proposed adding explicit syntax for inference requests: Something like `? x = new XType(some, argument, s);` would give `x` the type `XType`, statically, dynamically, and correctly. ;-)
Other than that you couldn't reduce the syntax much (sure, `x = XType some s` omits `var`, `;`, and `new`, and uses functional style invocation, and infers the argument `argument`, but there is a truckload of reasons why those things don't fit well into Dart).
On Monday, October 5, 2015 at 11:38:29 AM UTC+1, Erik Ernst wrote:I think the reason why `var x = new XType(some, argument, s);` does not work sufficiently well is that it violates the language semantics to infer the typeWhat are the language semantics?
(it's ok for an editor to offer completion based on an optimistic assumption that a given approach to inference produces a "correct" result, but it is not ok to throw a type error in checked mode if the programmer violates a typing constraint that the compiler invented).That's the reason why I've proposed adding explicit syntax for inference requests: Something like `? x = new XType(some, argument, s);` would give `x` the type `XType`, statically, dynamically, and correctly. ;-)Why not `let x = new XType(some, argument, s);` .
Other than that you couldn't reduce the syntax much (sure, `x = XType some s` omits `var`, `;`, and `new`, and uses functional style invocation, and infers the argument `argument`, but there is a truckload of reasons why those things don't fit well into Dart).Why?
On Mon, Oct 5, 2015 at 2:25 PM, kc <kevin...@gmail.com> wrote:On Monday, October 5, 2015 at 11:38:29 AM UTC+1, Erik Ernst wrote:I think the reason why `var x = new XType(some, argument, s);` does not work sufficiently well is that it violates the language semantics to infer the typeWhat are the language semantics?The semantics of a `var` declaration is that it declares a variable whose type is `dynamic`. This means that compilers cannot report typing problems with feature lookups (`x.foo(1,"blit")` is OK no matter whether there is a declaration of `foo` anywhere, and how it looks if it is declared) or when `x` is used in expressions, or in data flow (assignments of `x` to other variables, passing `x` as a parameter, returning `x`), no matter how wrong you may think it looks. And checked mode is not allowed to throw a `TypeError` if you assign a value to `x`, no matter whether it has type `XType` or not. In short, `x` is dynamic.
(it's ok for an editor to offer completion based on an optimistic assumption that a given approach to inference produces a "correct" result, but it is not ok to throw a type error in checked mode if the programmer violates a typing constraint that the compiler invented).That's the reason why I've proposed adding explicit syntax for inference requests: Something like `? x = new XType(some, argument, s);` would give `x` the type `XType`, statically, dynamically, and correctly. ;-)Why not `let x = new XType(some, argument, s);` .That would work, too. That may look more familiar to JavaScript folks and SML-ites, but I do think that it smells like "immutability" as well as "inferred type" (and only the latter is on the agenda here, as far as I can see).
Other than that you couldn't reduce the syntax much (sure, `x = XType some s` omits `var`, `;`, and `new`, and uses functional style invocation, and infers the argument `argument`, but there is a truckload of reasons why those things don't fit well into Dart).Why?That's a thousand other heated debates, there's no way we would benefit from taking all those discussions right here. ;-)
// Swift! A tuple with type inference!
let tup = (1.0, 2.0);
// Named tuples!
let tup2 = (x: 1.0, y: 2.0);
On Monday, October 5, 2015 at 1:55:22 PM UTC+1, Erik Ernst wrote:On Mon, Oct 5, 2015 at 2:25 PM, kc <kevin...@gmail.com> wrote:On Monday, October 5, 2015 at 11:38:29 AM UTC+1, Erik Ernst wrote:I think the reason why `var x = new XType(some, argument, s);` does not work sufficiently well is that it violates the language semantics to infer the typeWhat are the language semantics?The semantics of a `var` declaration is that it declares a variable whose type is `dynamic`. This means that compilers cannot report typing problems with feature lookups (`x.foo(1,"blit")` is OK no matter whether there is a declaration of `foo` anywhere, and how it looks if it is declared) or when `x` is used in expressions, or in data flow (assignments of `x` to other variables, passing `x` as a parameter, returning `x`), no matter how wrong you may think it looks. And checked mode is not allowed to throw a `TypeError` if you assign a value to `x`, no matter whether it has type `XType` or not. In short, `x` is dynamic.For Dart 2.0 does this semantics make sense - especially for developers who may come to Dart fresh under the impetus of Flutter?
(it's ok for an editor to offer completion based on an optimistic assumption that a given approach to inference produces a "correct" result, but it is not ok to throw a type error in checked mode if the programmer violates a typing constraint that the compiler invented).That's the reason why I've proposed adding explicit syntax for inference requests: Something like `? x = new XType(some, argument, s);` would give `x` the type `XType`, statically, dynamically, and correctly. ;-)Why not `let x = new XType(some, argument, s);` .That would work, too. That may look more familiar to JavaScript folks and SML-ites, but I do think that it smells like "immutability" as well as "inferred type" (and only the latter is on the agenda here, as far as I can see).I think type inference and immutability/single assignment play extremely well together. It's an easy win imo.
Other than that you couldn't reduce the syntax much (sure, `x = XType some s` omits `var`, `;`, and `new`, and uses functional style invocation, and infers the argument `argument`, but there is a truckload of reasons why those things don't fit well into Dart).Why?That's a thousand other heated debates, there's no way we would benefit from taking all those discussions right here. ;-)For Dart 2.0 the Dart team needs to offer a clear story for developers.(Along ideally with tuples/value objects - which I believe you are interested in). Dev's can see a soon to be open sourced Swift - which will have good perf - and could gain traction on the server and IoT - where Dart is hoping to make inroads.
// Swift! A tuple with type inference!
let tup = (1.0, 2.0);
// Named tuples!
let tup2 = (x: 1.0, y: 2.0);
The semantics of a `var` declaration is that it declares a variable whose type is `dynamic`. This means that compilers cannot report typing problems with feature lookups (`x.foo(1,"blit")` is OK no matter whether there is a declaration of `foo` anywhere, and how it looks if it is declared) or when `x` is used in expressions, or in data flow (assignments of `x` to other variables, passing `x` as a parameter, returning `x`), no matter how wrong you may think it looks. And checked mode is not allowed to throw a `TypeError` if you assign a value to `x`, no matter whether it has type `XType` or not. In short, `x` is dynamic.For Dart 2.0 does this semantics make sense - especially for developers who may come to Dart fresh under the impetus of Flutter?I don't expect this particular property of Dart to change (it's so deep that it is hard to tell what it won't break).
--
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.
Sure, but that violates the spec which means that is a bug.
So please help me fight for the ability to _request_ the inference explicitly. ;-)
It has already changed within the confines of dart4web and DDC's strong mode:// main.dartmain() {var i = 3;i = "not int";}$ dartanalyzer main.dartAnalyzing [main.dart]...[error] Type check failed: "not int" (String) is not of type int (/Users/rnystrom/temp/temp.dart, line 3, col 7)[warning] A value of type 'String' cannot be assigned to a variable of type 'int' (main.dart, line 3, col 7)[hint] The value of the local variable 'i' is not used (main.dart, line 2, col 7)1 error, 1 warning and 1 hint found.
To be honest, I tend to type things whenever I get the chance. Even sometines unnecessarily generic types to end up with very ugly Foo <Bar <Baz>> things.
Then again, I come from a typed language background, I imagine most current Dart lib authors do.
The JS devs barely look at Dart yet arguably the whole optional typing was created to lure them in. Since that failed, why indeed bother still?
@Bob: how many of these languages treat
var x=0;
x="hello"
as a warning?
I think it's getting a bit complicated. Strong mode, Checked mode... Not sure other languages have this. If they don't, then we are about to borrow just half a concept, which may lead to confusion.
How do I enable these strong mode error/warnings. If I just run dartanalyzer main.dart, I don't get those error/warnings.
// Explicit type
Point pe = new Point(1,1);
// type inference with mutable binding
var pm = new Point(1,1);
// type inference with immutable binding
let pi = new Point(1,1);
// Dynamic/duck type
Any pa = new Point(1,1);
class Point {
Any a; // less painful with a succinct 'duck' type
int p;
Point(this.a, this.i);
}
On Mon, Oct 5, 2015 at 3:09 PM, kc <kevin...@gmail.com> wrote:On Monday, October 5, 2015 at 1:55:22 PM UTC+1, Erik Ernst wrote:On Mon, Oct 5, 2015 at 2:25 PM, kc <kevin...@gmail.com> wrote:On Monday, October 5, 2015 at 11:38:29 AM UTC+1, Erik Ernst wrote:I think the reason why `var x = new XType(some, argument, s);` does not work sufficiently well is that it violates the language semantics to infer the typeWhat are the language semantics?The semantics of a `var` declaration is that it declares a variable whose type is `dynamic`. This means that compilers cannot report typing problems with feature lookups (`x.foo(1,"blit")` is OK no matter whether there is a declaration of `foo` anywhere, and how it looks if it is declared) or when `x` is used in expressions, or in data flow (assignments of `x` to other variables, passing `x` as a parameter, returning `x`), no matter how wrong you may think it looks. And checked mode is not allowed to throw a `TypeError` if you assign a value to `x`, no matter whether it has type `XType` or not. In short, `x` is dynamic.For Dart 2.0 does this semantics make sense - especially for developers who may come to Dart fresh under the impetus of Flutter?I don't expect this particular property of Dart to change (it's so deep that it is hard to tell what it won't break).(it's ok for an editor to offer completion based on an optimistic assumption that a given approach to inference produces a "correct" result, but it is not ok to throw a type error in checked mode if the programmer violates a typing constraint that the compiler invented).That's the reason why I've proposed adding explicit syntax for inference requests: Something like `? x = new XType(some, argument, s);` would give `x` the type `XType`, statically, dynamically, and correctly. ;-)Why not `let x = new XType(some, argument, s);` .That would work, too. That may look more familiar to JavaScript folks and SML-ites, but I do think that it smells like "immutability" as well as "inferred type" (and only the latter is on the agenda here, as far as I can see).I think type inference and immutability/single assignment play extremely well together. It's an easy win imo.Sure, but if the intention is only to allow for inference then the incorrect "immutable" connotation would just confuse people.
I've never seen language users question so much the fundamentals of the language they're using.
They're still using it, so the designers must be doing something right.
But there has been a shift in the platform's expectations.
Dart was meant to get into Chrome and to be push to other browsers. That's where I get the unsound type system: SECURITY.
That's where Flash failed. Any flaw could be used whatever the platform/OS, taking control back from the browsers.
Flash is ahead of its time. Although the language could be improved, the runtime is quite a feat of engineering, still to be matched today. And the graphics/media libraries ... the best I've seen on the market. 2 clicks to target any platform and get performance. Kudos to Adobe.
Too bad political/comercial interests got over web productivity.
Although the specs, runtime and some graphics libraries were open-source, nobody could match them. So they got killed.
Back to Dart >.<
I seriously urge Dart to reconsider its unsoundness. It prevents many analyses/optimizations oportunities, on many levels. Most code will be unaffected.
C# is going functional. Functional seems to go native.
The sweet spot is hard to find. Maybe we should provide abstractions AND a way to avoid them. And leave it to the programmer to decide.
On Mon, Oct 5, 2015 at 9:26 AM, 'Erik Ernst' via Dart Misc <mi...@dartlang.org> wrote:Sure, but that violates the spec which means that is a bug.But a bug in the spec, or in DDC? ;)
So please help me fight for the ability to _request_ the inference explicitly. ;-)
Absolutely not.We have a way to request inference. It's spelled "var".
Using that for inference makes
Dart consistent with TypeScript, Scala, C#, Flow, Kotlin, Swift, and probably some others I'm forgetting. Using the exact same syntax as those languages to mean something totally different (and almost always not what the user wants) is a complete usability failure.In fact, I've seen time and time again where Dart users expect Dart to actually do that and are surprised that isn't already the standard behavior.Likewise, we already have a perfectly valid, supported syntax to request no inference, "dynamic". We don't need two.
On Mon, Oct 5, 2015 at 6:33 PM, 'Bob Nystrom' via Dart Misc <mi...@dartlang.org> wrote:On Mon, Oct 5, 2015 at 9:26 AM, 'Erik Ernst' via Dart Misc <mi...@dartlang.org> wrote:Sure, but that violates the spec which means that is a bug.But a bug in the spec, or in DDC? ;)
Neither. It's just DDC not implementing the Dart spec.The language of DDC is not Dart. It's close, but it's not Dart, and that's not a bug, it's a feature.
Then again, there is no full implementation of Dart yet if we get really picky (the VM doesn't allow two labels on the same statement! It's NOT DART! *Muhahahahahah*).
So please help me fight for the ability to _request_ the inference explicitly. ;-)
Absolutely not.We have a way to request inference. It's spelled "var".Uhm, no. We have already used that for something else, so it is not, currently, a way to request inference.
We would have to change the spec to make that actually do (runtime) inference - that is, we still need the ability to request the ability, whether by changing how "var" works or in some other way.Using that for inference makesmakes -> would make.Currently it does not, not in Dart. It wouldn't mind changing that, but it's a breaking change, so we will ... need to fight for it.
It still has the problem that it doesn't work in the VM.Using the static type of the initializer expression as the runtime type of the variable would mean that the VM can't implement this without adding the static type system - for no other reason than to infer that type.I think it's more likely that the VM would remove checked mode than add static type checking.
Dart consistent with TypeScript, Scala, C#, Flow, Kotlin, Swift, and probably some others I'm forgetting. Using the exact same syntax as those languages to mean something totally different (and almost always not what the user wants) is a complete usability failure.In fact, I've seen time and time again where Dart users expect Dart to actually do that and are surprised that isn't already the standard behavior.Likewise, we already have a perfectly valid, supported syntax to request no inference, "dynamic". We don't need two.True. So let's work towards making "var" mean "infer type (if possible)".
Using the static type of the initializer expression as the runtime type of the variable would mean that the VM can't implement this without adding the static type system - for no other reason than to infer that type.
--
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.
On Tue, Oct 6, 2015 at 9:19 AM, 'Lasse R.H. Nielsen' via Dart Misc <mi...@dartlang.org> wrote:On Mon, Oct 5, 2015 at 6:33 PM, 'Bob Nystrom' via Dart Misc <mi...@dartlang.org> wrote:On Mon, Oct 5, 2015 at 9:26 AM, 'Erik Ernst' via Dart Misc <mi...@dartlang.org> wrote:Sure, but that violates the spec which means that is a bug.But a bug in the spec, or in DDC? ;)Hi Bob,it could have been a bug in the spec if nobody had noticed this and nobody had implemented the specified semantics, but I think you will find it difficult to support that interpretation.
Neither. It's just DDC not implementing the Dart spec.The language of DDC is not Dart. It's close, but it's not Dart, and that's not a bug, it's a feature.Hi Lasse,agreed, that's one way to explain the situation. But the point is that programmers need the language to be well-defined, and the purpose of specifying a language is exactly that.
If the language has an only-approximately-determined semantics then nobody can write a reusable library and expect it to work "in general", it will have to be tested from scratch with each variant of the language (which could then mean: each compiler, each analyzer, etc.).
makes -> would make.Currently it does not, not in Dart. It wouldn't mind changing that, but it's a breaking change, so we will ... need to fight for it.That's the most serious problem, as I see it: It is a breaking change that will potentially change the behavior of programs in hundreds of locations per library. That's the reason why I'm advocating new syntax for the new semantics. I want that semantics, too! ;)
Let's work towards getting support for inferred type annotations, in a way that doesn't potentially break all existing programs! ;-)
@Alex I fail to really see your point. You say you don't use var, so this won't affect you at all, right?
And it seems like that people that do use "var" for local variables, like the new behavior. If I would use var, I would absolutely love this.
"the utter ugliness of ActionGroup actionGroup = new ActionGroup(x,y,z) - is where ampersand comes in."
see my suggestion near top of post which solves this as follows:
ActionGroup actionGroup = new (x,y,y);
The constructor called by new() is inferred by the LHS type annotation.
@Bob:Some SW shops introduce very stringent coding standards, which require strong typing, be it hell or high water.According to these standards, if foo() returns Stream<List<int>>, people have to write it as
Stream<List<int>> stream=foo();If someone dares writing anything likevar stream = foo();he gets demoted to the role of dishwasher for life, or until he repents (whichever comes first)
Do you have any empathy at all?
How about backslashed names?
Ampersand? (Actually, I'd like to have both)
@Kasper: what tool did you use to produce beautiful animation?
--
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.
Agreed re factory constructors. You would still need
Foo foo = new Bar(x,y,z)
For named constructors you could use
Foo foo = new.named(x,y,z);
The point of my suggestion is to avoid the verbosity of types on both LHS and RHS which it would do in most cases. The var proposal in this thread effectively does the same but leaves the type information on the RHS.
--
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.
--
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.
Suppose, tomorrow dart adds extra feature to generics repertoire so we can write something likeIterable<T> map(T f(E element))Now dart CAN (in principle) figure out the return type of <int>[1,2,3].map((x)=>"Hello");
The problem is that adding a rule to the list of rules of type inference is a breaking change again!What was Iterable<dynamic>, cannot suddenly become Iterable<String>.
Personally, I don't like breaking changes, but I really don't like shipping a language that people aren't thrilled about. Maintaining rigorous compatibility with an unpopular product seems like a good way to ensure you're never popular.
@Bob: let me change sides for a moment - I will advocate for inference, but for more consistent inference.How big is the problem to remove all limitations? Let's focus on "var", just to get a sense of it.When there's an uninitialized var, compiler can take the type from any place it can see the assignment to this var (limit the search by same library, or even a file).
var a;closure() => a;a = closure();
All other assignments must have same type (not a common denominator - exactly the same), otherwise it's an error.If compiler cannot find any assignments - error.
Thus, "var" is not synonymous with "dynamic" any longer. It means "inferred type". And inferred type cannot be "dynamic".
var i = 123 as dynamic;
Whatever is supposed to be really dynamic, should be explicitly declared dynamic.Now you examplevar x;if (something) {//some workreturn 0;} else {// other workreturn 1;}will work just fine.
var x = if (something) {0;} else {1;}
var x = calculateValue(something);
var x = () {if (something) {return 0;} else {return 1;})();
No matter what someone can think about the usefulness of inference, "var as inferred type" now looks like a concept,Over time, compiler can add heuristics, covering more cases of inference, but nothing will be broken by those new rules - it's just there will be less places where compiler cannot figure out the type.How about that? Any known common counterexamples?
try {} would be another example.
var blah;try {blah = someThingThatCanFail();} on SomeError catch (error) {blah = ...
}blah.useIt();
This is a good example to bring up. I think the majority of the cases where you declare a local variable without an initializer are exactly like this—it gets initialized in both arms of a subsequent if, or maybe a switch.Many languages that do inference for locals tend to be more expression-oriented to avoid this trap. I wonder if that would work for Dart. If we made if () and {} expressions (with very very low precedence!) then you could do:var x = if (something) {0;} else {1;}In the absence of that, I sometimes work around this by hoisting that calculation to a separate function:var x = calculateValue(something);I suppose if I wanted to be clever, I could do:var x = () {if (something) {return 0;} else {return 1;})();But I think that style is perverse and wouldn't use it.
--
I find this very interesting, would like something like this, but how then would it work if there are multiple expressions in the if statement? Just returning the last one?
var x = if (something) {var split = something.split(' ');split..removeAll(otherthing);split.last;} else {1;}Implicit return looks a bit strange in dart.
Just a couple of small observations.
> In other words, "dynamic" means "I successfully inferred it to be dynamic", not "I failed to infer it".
I think propagating "dynamic" can lead to a chain reaction that might be quite unexpected for user. E.g.
var x=somethingThatReturnsDynamic(param1, param2);
var y=x*2; // but you know it's int
In many situations, function for whatever reason returns dynamic, but you "know" it's int in your scenario. What you DON'T know is that the function somethingThatReturnsDynamic returns dynamic, you thought it should be "int".
In this case, "dynamic" will propagate to "y" and further, with no end. I think it's better to put a barrier upfront. var y=x*2 should be an error to infer type
- unless you invoke universal Object methods like hashCode (BTW, I was surprised to see that current compiler infers the type of hashCode correctly, even for "dynamic" argument). So the issue of "dynamic" propagation is not quite clear-cut.
> At the same time, I think it's important for inference to be simple enough for users to have an intuition about how it works and feel safe and confident relying on it.
> I could be wrong, but my hunch is that going full flow-sensitive would be a bad fit for that.
I think first sentence is a bit inconsistent with the second. How anyone can feel "safe and confident" if things start losing types after minor refactoring, with no warning or anything?
--
Just one nitpick: when compiler sees uninitialized var, it should print error message asking to specify type, without mentioning "or initialize".
--
Many languages that do inference for locals tend to be more expression-oriented to avoid this trap. I wonder if that would work for Dart. If we made if () and {} expressions (with very very low precedence!) then you could do:var x = if (something) {0;} else {1;}
In the absence of that, I sometimes work around this by hoisting that calculation to a separate function:var x = calculateValue(something);
I suppose if I wanted to be clever, I could do:var x = () {if (something) {return 0;} else {return 1;})();But I think that style is perverse and wouldn't use it.
the type is correctly inferred as Iterable<int>.But inConsider the following example:What is the type of "result"? Turns out, it's Iterable<dynamic>.
var result =
<int>[1,2,3].map((x)=>"Hello");
var result =
<int>[1,2,3].where((x)=>x>0);
In case of map, there's no way to make inference work, even in principle, because there's no syntax to declare return type of mapping function.
But even if returned type somehow could be figured out, there's no syntax to write declaration of "map" function so that compiler can deduce return type correctly.
Today, declaration of "map" is: Iterable map(f(E element))
Suppose, tomorrow dart adds extra feature to generics repertoire so we can write something likeIterable<T> map(T f(E element))
Now dart CAN (in principle) figure out the return type of <int>[1,2,3].map((x)=>"Hello");The problem is that adding a rule to the list of rules of type inference is a breaking change again!
@Bob: let me change sides for a moment - I will advocate for inference, but for more consistent inference.How big is the problem to remove all limitations? Let's focus on "var", just to get a sense of it.When there's an uninitialized var, compiler can take the type from any place it can see the assignment to this var (limit the search by same library, or even a file).All other assignments must have same type (not a common denominator - exactly the same), otherwise it's an error.
If compiler cannot find any assignments - error.Thus, "var" is not synonymous with "dynamic" any longer. It means "inferred type". And inferred type cannot be "dynamic".Whatever is supposed to be really dynamic, should be explicitly declared dynamic.Now you examplevar x;if (something) {//some workreturn 0;} else {// other workreturn 1;}will work just fine.No matter what someone can think about the usefulness of inference, "var as inferred type" now looks like a concept,Over time, compiler can add heuristics, covering more cases of inference, but nothing will be broken by those new rules - it's just there will be less places where compiler cannot figure out the type.How about that? Any known common counterexamples?
It will break all substantial usages of dynamic types (say, some variable plays a conceptual role, but different representations are used along the way: `var document = "Hello"; .. document.toUpperCase() .. document = new MyDocumentType(); .. document.myFancyFeature() ..`).
@Erik, what do you think about the idea of allowing only initialized vars? So "var x;" without initializer is an error. Now "var" always means "inferred type". Isn't it a good idea?
--
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.
Am I really the only one around to think that it is seriously dangerous for a programming language that aims to be useful in production if its semantics is less than well-defined? ;)
But I'm not happy about "other than that, `var` means inferred type", because that isn't Dart as specified. Am I really the only one around to think that it is seriously dangerous for a programming language that aims to be useful in production if its semantics is less than well-defined? ;) I have no problems supporting these ideas, I just don't want them to make the semantics fuzzy.
I like initialized vars (meaning: variables whose declaration includes an initializing expression), and I'd recommend using `final` wherever possible, too. But entirely outlawing `var x;` might be a little bit too harsh.The cases that came up recently were about blocks returning values, and the motivation was that```MyType x = longAndComplexExpressionProbablyMultiLine? equallyLongThingWithThreeLevelsOfNestedBraces: etcEtc;```where the old-fashioned imperative style (just use `MyType x;` and then spend as many lines as needed on initializing it) seems to be justified now and then. I'll do a lot to avoid uninitialized variables in practice, though.But I'm not happy about "other than that, `var` means inferred type", because that isn't Dart as specified. Am I really the only one around to think that it is seriously dangerous for a programming language that aims to be useful in production if its semantics is less than well-defined? ;) I have no problems supporting these ideas, I just don't want them to make the semantics fuzzy.
> But I'm not happy about "other than that, `var` means inferred type"
But there's no "other than that"! "var" will mean "inferred type", period.
It doesn't ban uninitialized variables in general. It DOES ban uninitialized variable written as "var x;".
In your example, everything is fine- you didn't say "var x;" - you said "MyType x;" - there's no problem with that, type is explicitly defined.
But I'm not happy about "other than that, `var` means inferred type", because that isn't Dart as specified. Am I really the only one around to think that it is seriously dangerous for a programming language that aims to be useful in production if its semantics is less than well-defined? ;) I have no problems supporting these ideas, I just don't want them to make the semantics fuzzy.
1) I have proposed to use "let" for type inference and maybe strong mode. I see no need to change the meaning of "var".
2) Why not change the specification for the next Dart version ? Do I miss something ?
Besides, I do not read the dry specification of a language unless there is no better documentation available for a certain feature.
Language specifications aren't useful because everybody reads them, they are useful because bits and pieces of them can be studied carefully by tool implementers whenever there is a "How should the language behave in this situation?" question. Heck, even authors of books/blogs/whatever about the language might need to do the same thing, so hopefully you won't miss anything in the end. ;-)
Language specifications aren't useful because everybody reads them, they are useful because bits and pieces of them can be studied carefully by tool implementers whenever there is a "How should the language behave in this situation?" question. Heck, even authors of books/blogs/whatever about the language might need to do the same thing, so hopefully you won't miss anything in the end. ;-)
I fully agree.
I meant that any feature or behavior of a language should be intuitive or safe (= compilation error) enough so that I do not need to read the specification.
IMO, the strategy to allow non-obvious differences between language versions or different platforms is bad.
The notorious example: No arbitrary size integers when compiled to Javascript.
Anything non-obvious should be made clear in obvious ways and not just somewhere in the spec or on stackoverflow.com.
The spec of a language is comparable to the end-user license agreement for programs.
I do not want having to read it and some people might not even understand it even if they tried.
Besides I wonder how far Dart will differ from platform to platform and over time after reading https://github.com/dart-lang/dart_enhancement_proposals/blob/master/Meetings/2015-09-30%20DEP%20Committee%20Meeting.md
On Fri, Oct 9, 2015 at 7:04 PM, 'Bob Nystrom' via Dart Misc <mi...@dartlang.org> wrote:On Fri, Oct 9, 2015 at 9:41 AM, 'Erik Ernst' via Dart Misc <mi...@dartlang.org> wrote:Am I really the only one around to think that it is seriously dangerous for a programming language that aims to be useful in production if its semantics is less than well-defined? ;)
Well... :)Well, I'm not quite sure what your point is, but there might be a connection to the fact that the page about running python in a sandboxed environment that you are linking to mentions different versions of python (2.5 and 2.7) but it doesn't even mention version 3.0 (Py3k). Maybe you are saying that it is impossible to migrate an entire community from one version of a language to another (not so backward compatible) version, because they seem to carefully avoid Py3k?
On Mon, Oct 12, 2015 at 1:32 AM, 'Erik Ernst' via Dart Misc <mi...@dartlang.org> wrote:On Fri, Oct 9, 2015 at 7:04 PM, 'Bob Nystrom' via Dart Misc <mi...@dartlang.org> wrote:On Fri, Oct 9, 2015 at 9:41 AM, 'Erik Ernst' via Dart Misc <mi...@dartlang.org> wrote:Am I really the only one around to think that it is seriously dangerous for a programming language that aims to be useful in production if its semantics is less than well-defined? ;)
Well... :)Well, I'm not quite sure what your point is, but there might be a connection to the fact that the page about running python in a sandboxed environment that you are linking to mentions different versions of python (2.5 and 2.7) but it doesn't even mention version 3.0 (Py3k). Maybe you are saying that it is impossible to migrate an entire community from one version of a language to another (not so backward compatible) version, because they seem to carefully avoid Py3k?
Sorry, I should have been less snarky and more clear.
My point is that Google itself supports a language that is widely used for large production applications, and that language—Python—has no specification whatsoever.
A spec doesn't seem to be the most important stepping stone on the path to success. It's certainly valuable, but I think if we get too hung up on what the spec does and doesn't permit we may get distracted from the much more important question, what is and isn't most helpful for our users.
It is not endorsed by ECMA or ISO, but its intention and style seems to be quite similar to other language standardization documents .. e.g., in Sect. 5.2.1:
I'm not so hung up on a particular format, but I do think that it is useful for real-world programmers to know what their programs will do, also when the next version of a compiler comes out. I just think that a language specification is a reasonable means to that end.
It's more a question of process and attitude. ECMA/TC52 and 'The Spec' were part of the collective hallucination that Dart was going to be adopted by the other browser vendors. Well this thread is appropriately titled because that was fairy dust. And Dart is left with a fairly cumbersome language design process.
I'm not so hung up on a particular format, but I do think that it is useful for real-world programmers to know what their programs will do, also when the next version of a compiler comes out. I just think that a language specification is a reasonable means to that end.Right. The area where The Spec has failed is in communicating with real-world developers and creating a sense of shared understanding of it's core ideas and semantics. (Sometimes it seems even Dart team members are confused).
On Tuesday, October 13, 2015 at 9:32:55 AM UTC+1, Erik Ernst wrote:
It is not endorsed by ECMA or ISO, [..]It's more a question of process and attitude. [..]
You have expressed some interest in value objects/immutability. David Morgan has done some very interesting work in this area. If I was on the Dart team I would be *intensely* interested in how projects were using these concepts with an eye to providing lang support. Do the Dart team need to see a 4th or 40th third party implementation of value objects/types before something happens.
I'm indeed interested in first class values, but that's potentially a huge addition to the language so I don't expect that to happen very quickly. I'm maybe even more interested in fixing the function type subtype rule (return types should require covariance), and that's a near-one-liner change in the compilers. But things take time when they may potentially break existing code.
Here's another view on the speed: JavaScript went from ES5 (December 3, 2009) to ES6 (still in draft state almost 6 years later), whereas Dart had three versions of its language specification accepted as ECMA standards during the past <18 months. So the Dart standard is moving quite fast compared to others.
On Tuesday, October 13, 2015 at 2:35:37 PM UTC+1, Erik Ernst wrote:I'm indeed interested in first class values, but that's potentially a huge addition to the language so I don't expect that to happen very quickly. I'm maybe even more interested in fixing the function type subtype rule (return types should require covariance), and that's a near-one-liner change in the compilers. But things take time when they may potentially break existing code.Quickly? Have you even considered contacting David to get the ball rolling on values types?
On Tue, Oct 13, 2015 at 4:05 PM, kc <kevin...@gmail.com> wrote:On Tuesday, October 13, 2015 at 2:35:37 PM UTC+1, Erik Ernst wrote:I'm indeed interested in first class values, but that's potentially a huge addition to the language so I don't expect that to happen very quickly. I'm maybe even more interested in fixing the function type subtype rule (return types should require covariance), and that's a near-one-liner change in the compilers. But things take time when they may potentially break existing code.Quickly? Have you even considered contacting David to get the ball rolling on values types?Have you? ;)
On Tuesday, October 13, 2015 at 3:27:34 PM UTC+1, Erik Ernst wrote:On Tue, Oct 13, 2015 at 4:05 PM, kc <kevin...@gmail.com> wrote:On Tuesday, October 13, 2015 at 2:35:37 PM UTC+1, Erik Ernst wrote:I'm indeed interested in first class values, but that's potentially a huge addition to the language so I don't expect that to happen very quickly. I'm maybe even more interested in fixing the function type subtype rule (return types should require covariance), and that's a near-one-liner change in the compilers. But things take time when they may potentially break existing code.Quickly? Have you even considered contacting David to get the ball rolling on values types?Have you? ;)I enquired how Ad's were using values/immutability with Dart. Which seems to be more than anyone form the Dart team has done.I don't work for Google, I'm not on the Dart team and I'm not part of the language design team. It's your job - or another member of the Dart team - to reach out.
I don't quite understand this aesopian language. "Leeway"? What does it actually mean, in simple terms? That dart from now splits into 2 (or 3?) different languages/dialects?
Then why not just say so? Maybe it would be a good thing - there's a chance that useful features are added at least somewhere. Object literals, for example... They are absolutely necessary for UI programming.
But things often don't get publicly discussed (Example: Zone. Created in complete secrecy. What Spec? There's no documentation at all).
Part of the job is to set priorities, and making 'reflectable' work well has to go above language design at this point.