First, the code. Here's the link: http://try.dartlang.org/s/csQn
main() { int x = 10; double y = 10.3282; print(x is Dynamic); print(x is num); print(x is double); // Int is a double? (plausible granted) print(y is int); // Double is an int?? (bye bye precision?) print(x is bool); print(y is bool); }
And the results:
true true true true false false
That's right. Not only is an int a double, but a double is an int. I previously mentioned the fact that we are supposed to be connected to the dart VM through the dartboard is of significance, as this topic has come up within the dart groups. In particular, Peter Ahé mentions:
Dart is a new programming language. If you want to see it as we intended it to work, use the Dart VM.
On the Dart VM, int and double are different.
Now I realize that Dart is 1) still a new language under development and has bugs still to be worked out and 2) Primarily designed to be a dynamic language. However I can see issues arising from this in a few special cases. Additionally, based on Seth Ladd's blog post:
The is check is not affected by the declared types, instead it is checking what the type of the variable actually is.Unfortunately at this time I do not have the Dart VM compiled and installed on my local machine which is why I've been relying on the dartboard for the time being. If anyone has the VM installed please try running the above and let me know if your results differ.
As far as I know, Dartboart sends code to the server to be compiled to Javascript, and sends the JS back to the browser to be executed. So you are running in an environment where int is double.
ReplyDeleteThe previous comment is correct. Dartboard sends the dart code to the server where it is compiled to JavaScript and sent back. The code is then executed in JavaScript. For efficiency ints and doubles are both compiled to JS numbers (doubles).
ReplyDeleteYour program would output the following on the Dart VM:
true
true
false
false
false
false