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.

Reflection on Ruby on Rails 3

In 1976, I took a course at Tulane University entitled Comparitive Languages. I recollect it covered Snobol, Fortran, Cobol, APL, Algol, Pascal, & Lisp but my memory is fuzzy. It was taught by a lecturer from industry. There was no computer science major at the time. I loved this course because it explored very different ways of programming.

I transferred to CMU where faculty created Alphard (in the hopes of winning the DoD's language contest), Bliss (a systems programming language), & OPS (a rule-based language). At a summer job at Texas Instruments, I learned Jovial (the Air Force's language). A famous professor taught us the moniker F***tran.

In grad school at UC Berkeley, I worked with declarative languages for circuits: EDIF, CIF, STL, STIF. The awful language tcl (Terrible Computer Language :)) was invented there.

In my first job (SDA which became Cadence Design Systems), one of our products was a Lisp dialect dubbed Skill. I programmed in C through my first three jobs. I used C++, Perl, & Javascript in my 4th job, excite, during the early days of the web. In my 5th job, IGN Entertainment, I used Java & Perl. We bought companies which used C# & Php (Pretty Horrible Programming language :)). In my 6th job, vudu, I used Java but Python, Lua, Ruby, & C++ were used by teammates. I used Python for Collectrium's proof of concept.

My most recent experience is using Ruby on Rails for Hands for Science. Ruby is a clean, elegant language. Interesting features include blocks/lambdas/Procs, default arguments, collecting hash arguments, dynamic types, symbols, mixins/modules, multi-line strings, string interpolation, eval, hash initializers.

Having used Python, Ruby, & Javascript heavily, I'll never understand the appeal of dynamic types. Dart is a new language which offers static & dynamic types. Related to this is collecting hash arguments. Keyword arguments are more robust & Dart has them.

Rails is a vast web framework. Declarative model validation & the asset pipeline are nice features. The worst problem is the long load time slows the iteration cycle. Other big problems include the form builder's weak support for relationships & the deep, obtuse stack traces. I'm not a fan of the verbose template language but there are many alternatives.

The asset pipeline supports Coffeescript. Perhaps its best feature is the addition of classes to Javascript.

I doubt I'll use this stack in the future. Currently, I'm studying node.js & Dart.