small medium large xlarge

Dart 1 for Everyone: Fast, Flexible, Structured Code for the Modern Web


Cover image for Dart 1 for Everyone

Dart 1 for Everyone

Fast, Flexible, Structured Code for the Modern Web


Psst! You’re not stuck with JavaScript anymore. Google’s Dart language makes programming for the Web simpler, faster, and more powerful. With version 1.0 in 2013 and an ECMA standard in 2014, Dart is ready to radically change web development for the better. And Dart 1 for Everyone has got you covered. Completely updated for Dart 1 and the ECMA standard, with new sections on new Dart features like method cascades, event streams, and class constructor syntax, this book wastes no time in immersing you in the finer points of this powerful and surprisingly beautiful language.

The first edition of this book was released as "_Dart for Hipsters_.":

Customer Reviews

A fun and easy read for anyone wanting to understand what Dart is and how to
use it with current generation browsers. The commentary on features planned
for future releases of Dart is reason enough to buy this book.

- Matt Margolis

At first I was somewhat skeptical of Dart. This book made me understand its
promise, gave me a good idea of its current state, and will serve as a solid reference
for me to lean on.

- Juho Vepsäläinen

This is the first book on this exciting and promising programming language, a
clear and approachable text that engages the reader and that certainly will contribute
to Dart’s success. I particularly liked his treatment of the functional aspects
of the language and the discussion of isolates.

- Dr. Ivo Balbaert

See All Reviews

What You Need

You will need the Dart SDK, which is freely available from Most of the book works with Dartium, a preview release of Chrome that is included in the SDK and has the Dart VM built-in. Some of the examples use either the dart2js tool or the Dart Editor to compile Dart down into JavaScript—both are part of the SDK.

5 Things You Don’t Know About Dart

5. It has brilliant server and browser package management. The “Pub” package manager works the same whether you are writing server code or a web application. List your dependencies in a pubspec.yaml file, run “pub get”, and your dependencies (and their dependencies) are immediately available. Whether it is compiled to JavaScript or run natively in the browser, Dart’s libraries and packages make organizing code a breeze.

4. It’s not really statically typed. You can declare variables with or without types—it makes no difference whatsoever at runtime. If you like declaring variables with var, go right ahead. If you like documenting code with types, feel free (it’ll help with docs and code analysis tools).

3. It has beautiful unit (and acceptance) testing built into the language from the outset. To build bulletproof applications, you need a strong testing suite. And Dart has you covered. Brilliantly.

2. Dart does not compile directly to JavaScript. To support all modern browsers (even IE10+), dart2js compiles to a JavaScript compatibility layer. That JavaScript compatibility layer is quite large, so dart2js performs sophisticated tree shaking so that it can drop unused bits, keeping the compiled code and compatibility layer as small as possible. The Dart team works hard to ensure that this compatibility layer works across the modern web so you don’t have to. No more browser checking. No more weird browser-specific bugs. Your code just works. Everywhere.

1. It rivals Ruby for code beauty. In addition to its simple, classical inheritance, Dart is loaded with syntactic sugar to make a programmer’s life easier. To name just a few, Dart has:

  • Method cascades (calling multiple methods on the same object).
  • First-class support for optional parameters (no more parsing an options hash, yay!)
  • Getter and setter methods (methods that look like properties, but are backed by a normal method).
  • Assignment of instance variables in the constructor declaration instead of the body.
  • String interpolation—no more chains of plus signs!

It’s the little things really. And Dart has so many little things that add up to greatness.

0. (BONUS!) It is fast. In many cases, the compiled JavaScript is faster than the JavaScript that you can hand-code. Don’t believe me? Check out the benchmarks and try it yourself!

Contents & Extracts

  • Introduction
  • Getting Started
    • Project: Your First Dart Application
      • The Back End
      • HTML for Dart
      • Ajax in Dart
      • This App Won’t Run
      • What’s Next
    • Basic Types
      • Numbers
      • Strings
      • Booleans
      • Maps (aka Hashes, Associative Arrays)
      • Lists (aka Arrays)
      • Dates
      • Types
      • What’s Next
    • Functional Programming in Dart
      • Anonymous Functions
      • First-Order Functions
      • Optional Arguments
      • What’s Next
    • Manipulating the DOM
      • dart:html
      • Finding Things
      • Adding Things
      • Removing Things
      • Updating Elements
      • Method Cascades
      • DOM Ready
      • What’s Next
    • Dart and JavaScript
      • Compiling to JavaScript with dart2js
      • Maintaining Dart and JavaScript Side-by-Side
      • Using JavaScript in Dart
      • What’s Next
  • Effective Coding Techniques
    • Project: MVC in Dart
      • MVC in Dart
      • Hipster Collections
      • Hipster Models
      • Hipster Views
      • Putting Models, Collections, and Views Together to Create New Records
      • What’s Next
    • Classes and Objects
      • Class Is a First-Order Concept
      • Instance Variables
      • Methods
      • Static Methods and Variables (aka Class Methods and Variables)
      • Subclasses
      • Duck-Typing in Dart with implements
      • Mixins
      • Constructors
      • What’s Next
    • Events and Streams
      • Plain-Old Events
      • Making Custom Events with Streams
      • What’s Next
  • Code Organization
    • Project: Extracting Libraries
      • What to Extract and What to Leave
      • Real Libraries
      • What’s Next
    • Libraries
      • Parts
      • Libraries
      • Core Dart Libraries
      • Packaging with “pub”
      • What’s Next
  • Maintainability
    • Project: Varying Behavior
      • Vary Class Behavior with noSuchMethod()
      • Sync Through Dependency Injection
      • What’s Next
    • Testing Dart
      • Obtaining the Test Harness
      • 2 + 2 = 5 Should Be Red
      • What’s Next
  • The Next Level with Dart
    • Project: An End to Callback Hell
      • The Future
      • Handling Errors in the Future
      • What’s Next
    • Futures and Isolates
      • Completers and Futures
      • Isolates
      • What’s Next
    • HTML5 and Dart
      • Animation
      • Local Storage
      • WebSockets
      • Canvas
      • Wrapping Up


Chris Strom is a relentless public learner, with more than 1,500 blog posts serving as research notes for his books. He has more than 10 years experience programming in Perl, Ruby, JavaScript, or whatever his current obsession happens to be. Chris lives in Baltimore, MD with his wife, 4 children, and a goldfish named Martin Tanner.