Monday, January 28, 2013

google's Dart Language

Javascript is a language invented by Netscape. It is the only language which all browsers can execute. (IE adds Basic & perhaps others.) Netscape's LiveWire product allowed Javascript to execute in the web server. node.js is the second coming of this isomorphic language.

Javascript has dynamic typing, simple formal parameters (including varargs), and an inheritance mechanism known as prototypes. There are several languages that aim to be more expressive & compile into Javascript.

Coffeescript: It uses Python-style indentation. Its class feature is the main reason to consider it. It has some other nice features like: destructured assignment as in [x, y] = 1 2, existential operator as in x ?= 1,  embedded JS as in `var x = 3;`, a switch statement which supports strings, string interpolation, multi-line strings, function binding (aka fat arrow =>) whereby this's value can be preserved in the call. Coffeescript is supported by Rails 3's asset pipeline.

Dart: Some notable features:
  • types: optional static typing as in var i; vs. int i;, typedefs (an evolving feature), constants as in const double PI = 3.14159;
  • operators: divide returning an integer result as in 4 ~/ 3
  • strings: multi-line, concatenation as in s1 s2
  • collections: Map literals as in { 'color': 'red', 'n': 13 } -- too bad the keys must be quote-delimited
  • functions: anonymous, syntactic sugar for single-expression methods/functions as in sum = (a, b) => a + b;, closures, optional positional & named formal parameters
  • inheritance: library-level instance variable visibility via _ identifier prefix as in _privateInamed constructors -- more readable than overloading, factory constructors, constructor initializers as in Person(this.name), getters/setters, abstract methods/classes, implicit interfaces (if you know Java, there is an implements keyword but not an interface keyword), operator overloading, generics as in Map<String, Integer> 
  • modularity: libraries (a refinement of Java packages)
  • comments: documentation comments (as opposed to a convention imposed by a document generator)
  • multiprogramming: isolates (instead of threads)
Notable omission: enumerations.

There are others which I won't cover here.

No comments:

Post a Comment