Posts

Showing posts from March, 2013

First Look at Dart Mixins

Image
You can use mixins to help inject behavior into your classes without using inheritance. Use a mixin when you have shared functionality that doesn't fit well in a is-a  relationship. Dart supports a basic form of mixins as of the M3 release in early 2013. The language designers expect to expand on mixins' abilities in future versions of the language. Surprisingly, you've been using the concept of a mixin all along. Dart considers a mixin as the delta between a subclass and its superclass . That is, every time you define an is-a  relationship with the extends  keyword, you are really defining a delta between the new class and its parent class. In other words, a subclass definition is like a mixin definition. Given that short description, it should come as no surprise that an abstract class (with a few restrictions) is itself a mixin. Here is an example of a Persistance mixin: abstract class Persistence { void save(String filename) { print(...

Dart on FLOSS Weekly from TWiT Network

Image
Today I had the pleasure of chatting about Dart with Randal Schwartz and Aaron Newcomb on FLOSS Weekly  (part of the TWiT network ). We talked about the Dart language, its developer ecosystem, and the future of the project. You can watch the entire video of the interview, embedded below for easy viewing: Thanks to Randal and Aaron for a lively discussion. They are awesome hosts and I highly recommend you tune in. Have Dart questions? Join us on the mailing list or the Dartisans G+ Community . We love feedback!

Solving Boggle with Dart

Image
My friends at work and I have been playing a lot of Scramble with Friends. It's a "tile based word searching game" where you find words on a 4x4 grid of letters. Being a good Dart hacker, I wanted to try writing a small library to find all possible words on the board. Here's how I did it! Dart, not trad. :) First off, props to danvk.org and his helpful posts (such as this one ) on solving Boggle. Old 'n busted My first attend was the naive version. The following code simply tried every possible combination, in a depth-first search. It works, but it's slow. So very slow. class Solver { final Map _words; final List<List<String>> _grid; final List<List> _visited = new List.generate(4, (_) => new List.filled(4, false)); final List _found = new List(); Solver(this._words, this._grid); _solve(int x, int y, [String word = '']) { _visited[x][y] = true; final newWord = '${w...

I Shrunk my Dart-to-JS code by 11X and So Can You

Image
Dart , the structured and scalable programming language for web apps, compiles to JavaScript thanks to dart2js . This means Dart apps run across the modern web. When you compile to JavaScript, you want to ensure dart2js generates the smallest amount of bytes. Less bytes means smaller bandwidth bills, and faster load times, and longer battery life. All good things! Read on to learn how to minify your generated JavaScript. For this example, I will use the offline-enabled Todo app that I built to highlight Lawndart , my easy library for browser storage. The Todo app uses quite a few libraries: dart:html Lawndart WebSQL IndexedDB Local storage Web UI The original generated JavaScript output size was 612,249 bytes. Minified, it became 289,840 bytes. Minified and gzipped it became 56,496 bytes. That's about 11X smaller than the original output! (Measuring the original size of the code is tricky. Do I count the lines that I wrote? Do I count the lines generated by the Web UI...