Posts

Slides from Dart talk at O'Reilly's FluentConf JavaScript conference

The fine folks at FluentConf included a Dart session in their first JavaScript conference. I had the pleasure of presenting "Structured web programming with Dart", an introduction to Dart's motivations, language, libraries, tools, and ecosystem. The room was packed, which was quite encouraging! I learned that Dart's optional static type annotations are very interesting to JavaScript developers. They especially appreciated the optional part. That is, in Dart you can experiment with simple functions and scripts as you start your idea, and grow over time to full complex modern web apps that use more structure like classes, interfaces, and libraries. Once your design emerges and you are comfortable with the structure, or once you enter maintenance mode, you can add the type annotations. Once those type annotations are in your code, the magic turns on. Type annotations provide inline documentation for your fellow developers. The toolchain can also read the type annot...

My interview with O'Reilly on Dart and doing better.

Image
I had the pleasure of being interviewed by Simon St. Laurent on the topics of Dart and how we can all strive to do better. Thanks Simon! The orignal post has the chapter markers and topics if you want to skip around.

Misleading strong type systems

This post is a record of a Dart Misc mailing list post  titled "Types are useless (?)". The original author was curious why Darts "allows running code with invalid arguments".  My reply follows: --- For reference, let's look at Java. Many would think that Java has a "strong type system" and that its types prevent, as you say, invalid arguments. However, it's easy to write a Java program that will compile just fine, yet fail at runtime. In your words, it will allow running code with invalid arguments. Here's an example: import java.util.*; public class hacked {   public static void test(int i) {     System.out.println(i);   }   public static void main(String[] args) {     String msg = "hacked";     Map cache = new HashMap();     cache.put("hacked", msg);     // later     int hacked = (Integer) cache.get("hacked");     test(hacked);   } } This code will comp...

When Dart types aren't optional

Dart, the structured web programming language, has a feature typically called "optional types". Dart claims that "type annotations don't affect the runtime semantics of the code". This post helps to explain when a type is and isn't optional, and what "type annotation" means as different than "type". The Dart discussion mailing list kicked off a good thread about generics , which evolved into when types can be optional. The Dart community chimed in with great answers (thanks to Ladislav, Sam, John, Dirk, Ross, Bob, and Eli!). Bob Nystrom summed it up well, with some examples that I wanted to specifically highlight: Bob writes: --- Types aren't always annotations. There are type annotations, but there are also places where types appear in code that are not annotations. For example: // type annotations:  int i; foo( int i) => ... class Foo {   int bar;   int baz() => ... }  // types that are not annotation...

Dart Crypto early access

The Dart project just saw its first crypto libraries land , specifically for SHA1 and SHA256. Also appearing is HMAC support. Learn how to use these very new libraries in this post. This new functionality is very new. You'll need to pull the latest from the bleeding_edge branch, as of 2012-04-30. It's so new, it's not even wired into the dart: library scheme, nor is it in the SDK yet. I expect crypto libs to get the full SDK treatment very soon. Here's an example of how to create a SHA256 hash and convert to a hex string: #import('../dart/lib/crypto/crypto.dart'); // Want this in the crypto lib? Star this bug: http://code.google.com/p/dart/issues/detail?id=2839 String digestToString(List<int> digest) {   var buf = new StringBuffer();   for (var part in digest) {     buf.add("${(part < 16) ? "0" : ""}${part.toRadixString(16).toLowerCase()}");   }   return buf.toString(); } main() {   var sha = new SHA256()...

Dart Server supports Web Sockets

[EDIT: Updated on 2013-12-05] Dart is a structured web programming language that runs on the client and the server. Web sockets are bi-directional data channels for real-time streaming communication between modern web browsers and servers. Thanks to a recent commit , Dart Servers can host Web Socket connections now! You'll need a copy of the Dart SDK as of 2013-03-05 for this to work. Dart already ships with basic HttpServer functionality. The new Web Socket is built on top of HttpServer, so it slides right into an existing Dart server app. The following code snippet is a simple example of a Web Socket echo server running in Dart. import 'dart:io'; void main() { HttpServer.bind('127.0.0.1', port) .then((HttpServer server) { print('listening for connections on $port'); server.listen((HttpRequest request) { if (request.uri.path == '/ws') { WebSocketTransformer.upgrade(request).then((WebSocket w...

4 new changes to the Dart language spec

The Dart team published version 0.08 of the Dart language spec , including 15 changes. I've detailed four of the most exciting changes below, some of which you might have seen as early proposals. Not all of these changes are implemented yet, but they show what direction the language and team is moving. Lazily Initialization for static variables This change was proposed  in February 2012. Previously, static class variables and top level variables had to be compile time constants. This kept initialization costs at startup low, but otherwise was constraining to the developer. With this change, static class variables and top level variables will be initialized at first access (lazily) and no longer need to constant. This is a developer friendly change that keeps initialization costs low. Version 0.08 of the spec now reads "Static variable declarations are initialized lazily. The first time a static variable v is read, it is set to the result of evaluating its initial...