
Dart uses types in a way that might seem strange. Most popular languages that offer a type system use it very differently. If you’re familiar with types in Java, Haskell, Scala, or any statically typed language, you may wonder why on earth Dart makes the choices that it does.
Background: Dart is a dynamically typed language, and proud of it
Dart types are dynamic, as in LISP, Smalltalk, Python, and JavaScript. Users of languages that also use dynamic typing, especially for programming JavaScript web certainlyunderstand the reason for this. If you prefer static typing in this article are not going to try to convince that it is better. For now we assume that Dart is a dynamically typed language.
In a dynamically typed language, any variable may be bound to a value of any type. Each value carries a tag identifying its type (or at least we can think of the implementation that way).
Dart adds some static typing, but it maintains the goal to have programmers take full advantage of its dynamic typing. The static type heuristics will not restrict them. (We talk about “type heuristics” because you really don’t want to think of it as a “type system”, not even an unsound type system.) So we want the static type checking to be optimistic: assume code is valid unless we can be statically sure it isn’t. This goal drives many of Dart’s decisions.
Source: Dartlang
Recent Comments