Showing posts from May, 2012

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

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) {

  public static void main(String[] args) {
    String msg = "hacked";

    Map cache = new HashMap();
    cache.put("hacked", msg);

    // later
    int hacked = (Integer) cache.get("hacked");


This code will compile, yet fail at runtime. (Yes, I could have used
generics t…

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 annotations:

foo is String;
new Foo();
new Foo<Ba…