Pretty print Dart collections

Thanks to a recent commit from Josh Bloch, you can now pretty print your Dart collections. This makes debugging and scripts much easier to write.

Example


main() {
  var list = [1,2,3];
  print("List: $list");


  var map = {"hello": "world", "1": 1};
  print("Map: $map");


  var set = new Set();
  set.add("foo");
  set.add("bar");
  print("Set: $set");
}

The VM's old 'n busted results:


List: [1, 2, 3, ]
Map: Instance of 'LinkedHashMapImplementation'
Set: Instance of 'HashSetImplementation<Dynamic>'


The VM's new hotness results:


List: [1, 2, 3]
Map: {hello: world, 1: 1}
Set: {bar, foo}

Recursion

That's pretty, but what about something tough? How does it handle recursive references?

list.add(list);
print("Recursive list: $list");

Old 'n busted:

[I never let it stop running, totally busted]

New hotness:

Recursive list: [1, 2, 3, [...]]

You'll need the very latest source from the bleed_edge branch to see this in action. It won't be long until this lands in trunk, though.

Enjoy!

1 comment

Popular posts from this blog