

Wrapping My Head Around Optional Typing (in Dart) - jashkenas
http://journal.stuffwithstuff.com/2011/10/21/wrapping-my-head-around-optional-typing/?

======
jashkenas
A lot of the conversation about how Dart is going to run faster than
JavaScript (or might someday) focuses on Dart's static types. This essay is a
great explanation of how Dart's types are a complete red herring when it comes
to performance -- they're used for optionally enabling runtime assertions, or
optionally running compile-time checks, but nothing more. They have no
influence on the semantics of your program, or how the Dart VM will optimize
it.

This is interesting, because it seems to mean that any of the performance
advantages Dart might have over JavaScript in the future ... could also just
as easily be added to JavaScript, by:

* Restricting changes to the shape of an object after it has first been created. Perhaps via a keyword.

* Adding a true integer type.

And for the curious, there's already a decent discussion happening over on
Proggit:
[http://www.reddit.com/r/programming/comments/lkpil/wrapping_...](http://www.reddit.com/r/programming/comments/lkpil/wrapping_my_head_around_optional_typing/)

~~~
pwpwp
I find "production mode" and the motivation for it in this article highly
irritating. If I declare a variable to hold only numbers, I'd expect that to
hold, no matter what (or get a runtime error immediately). I wouldn't want my
program to "stay the course" when my declared type assertions are wrong.

~~~
cwp
Then just run in checked mode.

------
chintan
Great article! Thanks for writing this up.

If there are no runtime performance benefits, then I wonder how is it
different from the Type Expressions in Google Closure [1]?

1\. [http://code.google.com/closure/compiler/docs/js-for-
compiler...](http://code.google.com/closure/compiler/docs/js-for-
compiler.html#types))

~~~
munificent
Thanks!

Dart's type annotations in a lot of ways are inspired by Closure. The big
difference is that Closure Compiler style JS is... well... hideous. You get
some of the maintainability and modularity of a statically typed language (I
can't count the number of times the Closure Compiler found errors for me), but
the way you have to write JavaScript to get that makes it incredibly ugly.

