Showing posts from September, 2012

final variables in Dart

(Shameless stolen from my own Stack Overflow question and answer .) Dart has a concept of  final . Most dynamic languages don't have this concept. What is final and what do I use it for? final  variables can contain any value, but once assigned, a final variable can't be reassigned to any other value. For example: main() { final msg = 'hello'; msg = 'not allowed'; // **ERROR**, program won't compile } final  can also be used for instance variables in an object. A final field of a class must be set before the constructor body is run. A final field will  not  have an implicit setter created for it, because you can't set a new value on a final variable. class Point { final num x, y; Point(this.x, this.y); } main() { var p = new Point(1, 1); print(p.x); // 1 p.x = 2; // WARNING, no such method } It's important to realize that  final  affects the variable, but not the object pointed to by the variable. That is,  final  doesn

15 cool features of Dart

I wrote an answer on for the question " What are some useful features of the Dart programming language? " The answer, or 13 answers, was too epic to be contained. It is copied here for your reading enjoyment. (Like the answer? Please vote it up. Thanks!) 1)  Optional static types.  When I'm prototyping or simply writing small scripts, I don't use a ton of static types. I just don't need 'em, and I don't want to get bogged down with the ceremony. However, some of those scripts evolve into bigger programs. As the scripts scale, I tend to want classes and static type annotations. 2)  Innocent until proven guilty.  Dart tries hard to minimize the situations that result in a compile-time error. Many conditions in Dart are warnings, which don't stop your program from running. Why? In keeping with web development fashion, it's imperative to allow developers to try a bit of code, hit reload, and see what happens. The

What Dart Wants

In which a long-time JavaScript community member learns what Dart wants, and is pleasantly surprised. (Note, I'm speaking from my personal perspective in this post.) A reasonable question I received a nice email from Addy Osmani , my friend and colleague in Chrome Developer Relations. Addy is active with the JavaScript community, maintains TodoMVC archive , authors  web development tutorials , and more. It's fair to say that Addy is plugged into modern web development. Beastie Boys, So What Cha Want? (C) 2009 Capitol Records, LLC As a current web developer, Addy was curious about Dart's motivations and philosophy. Is Dart out to replace JavaScript? Who is checking out Dart? What is Dart doing? What does it want ? Luckily, Addy came to the right place. Here's what I wrote back. Choice is good We believe developer choice is good, and options are good. We believe Dart, which can provide a compelling option for modern web app development, ultimately brings