Skip to main content


Showing posts from May, 2012

Updates to Dart style guide

Posted by Bob Nystrom

Just a quick note that I've updated the Dart style guide on The changes mostly reflect practices we've already adopted internally, but it's good to write them down so we can try to be as consistent as possible. While coding style is an eternal holy war, I think most of us agree that having a single style that the community uses makes it easier for all of us to share, reuse, and extend code.

Use ";" for empty constructors. This is required for const constructors. So, to be consistent, we use this for all empty constructors (which are pretty common thanks to initializing formals).

Place the super() call last in initialization lists. Dart lets you put it anywhere, but it always gets invoked after the other fields are initialized. Placing it last makes that visually consistent.

Prefer type annotating public APIs. Most of us seem to naturally do this anyway, so this just codifies that. You don't *have* to type annotate all over the…

Dart Editor improves on code completion in new build

Posted by Devon Carew

A new Dart Editor build is now available. Highlights from build 8124 include:

New, improved Editor documentation!Improved code completion in the absence of explicit type informationwe now have improved type inference in if, while, for and for-in statementsAll launches now run in checked mode by defaultAll launches (JavaScript and Dartium) now serve from a server and not from a file: urlthis plays better with loading resources using XHR and the browser security modelAnalysis results now cached between sessions ==> faster startup speedsFix for an issue with lots of warnings related to final fieldsFix for a performance issue with the outline view
Read the full change log or start with the Dart Editor documentation.

Thanks for trying the Dart Editor!

Dart VM gets C/C++ extensions

Posted by Seth Ladd

We just published "Native Extensions for the Standalone Dart VM", a new article from Dart engineer William Hesse. Bill shows you how to take your existing C/C++ code and expose it to Dart libraries via the Dart virtual machine.

A preview from the article:

"You can provide two types of native extensions: asynchronous or synchronous. An asynchronous extension runs a native function on a separate thread, scheduled by the Dart VM. A synchronous extension uses the Dart virtual machine library’s C API (the Dart Embedding API) directly and runs on the same thread as the Dart isolate. An asynchronous function is called by sending a message to a Dart port, receiving the response on a reply port."

We look forward to your feedback. Please join the Dart mailing list and share your experiences and code. Thanks for using Dart!

Run Dart in Apache web server

Posted by Seth Ladd

Today, Sam McCall announced mod_dart: the ability to run Dart apps embedded in Apache! Just like PHP, Perl, Python, and many other scripting languages, you can now use Dart to power your server-side web apps from inside the Apache web server.

From Sam's post:

I embedded the Dart VM in an Apache module, which allows it to host web applications written in Dart.
Install mod_dart, and drop this hello.dart file in your web server directory:
  #import('dart:apache');   main() {     response.headers.set('Content-Type', 'text/html');     response.outputStream.writeString('<h1>Hello, dart!</h1>');   }
What happens? Every time someone visits /hello.dart, main() is called within a new isolate. The dart:apache library provides access to the HttpRequest and HttpResponse objects, which are like in dart:io (except the input/output streams are synchronous). You can add entries in httpd.conf to snapshot your scripts on startup, which makes th…

Significant speed improvements for new Dart Editor

Posted by Devon Carew

A new Dart Editor build is now available. Highlights from build 7905 include:

The new analysis engine is turned on - performance for large projects should be significantly improveddart2js is now the default JavaScript compiler in the editor. See this note from Kasper for more info.Initial support for resolving package: importsType propagation support! code completion now works with many var variables:var foo = "mystring"; // code completion for foo will give you methods for the class StringAdded the ability to customize key bindingsUI improvements in the Search box / UI, and in the manage launches dialogBug fixes to the rename refactoringChecked mode is now default mode for running VM and Dartium apps
Read the full change log or start with the Dart Editor tutorial.

dart2js now the default compiler in Dart Editor

Posted by Seth Ladd

Today, Kasper Lund announced that dart2js, the Dart to JavaScript compiler, is now the default compiler in the Dart Editor.

From his post to the mailing list:

As the natural next step towards deprecating frog, we're making
dart2js the default Dart-to-JavaScript compiler in the Dart editor
today. The change is still pending
(, but I will post an
update once it lands (UPDATE: it's landed). Frog is still available in the SDK and the
editor still uses it for compilation, but you have to opt-in to using
it from your HTML files by changing your script tags to explicitly
request it through the data-compiler attribute:

  <script src=... data-compiler="frog">

As always we appreciate your feedback and we're looking forward to
finishing the transition to dart2js.


Meet some Dart VM engineers in this video interview

Posted by Seth Ladd

Yesterday we had a fun time hanging out with some of the Dart VM engineers. The video is now available from the interview, we hope you enjoy learning more about the Dart virtual machine from the engineers who are building it.

Thanks to Todd, Siva, Ivan, and Srdjan for chatting with us. And thanks to everyone who watched and sent in questions.

You can watch all archived episodes of Dartisans, too.

See you next time on Dartisans, the G+ Hangout broadcast for the Dart community!

Types and casting in Dart

Post by Seth Ladd

Bob Nystrom, engineer on the Dart team, posted a nice response to some questions posed to the mailing list about types, assignments, and casting. I thought this was a good way to phrase the issues, so I am posting here for others to find and enjoy.

Bob's reply to "Using num, one can assign a double to an integer without error or warning?":


  num n = 3.56;

Here, we assign a floating point literal whose static type is double to a
variable annotated to be type num. num is a supertype of double so you're
doing an upcast here. Like most languages an upcast is always safe and OK.
No warnings here.

  int x = n;

Here, the static type of n is num and we are assigning it to a variable
whose annotated type is int. int is a *sub*type of num, so in this case we
are doing a downcast. In most statically typed languages, you would need an
explicit cast operator, like:

  int x = (int)n;

Dart is different here. It has something called "assignment compatib…

4 Dart sessions at Google IO

Posted by Seth Ladd

UPDATED: the session dates and times.

The Google IO sessions have been announced, and Dart has a solid presence this year. If you didn't get a ticket, don't worry. Some of these sessions will be live streamed, and nearly all sessions are recorded and posted to YouTube later.

Dart - A Modern Web Language

Lars Bak and Kasper Lund, two of the Dart creators, will present "Dart - A Modern Web Language". They will discuss the rationale behind Dart's design and its impact on web scalability and performance. They'll also present how Dart helps developers innovate by increasing their productivity without breaking backwards compatibility. This session will be at June 27, 1:30PM - 2:30PM PDT.

Putting the App back into Web App - Web programming with Dart

Dan Grove and Vijay Menon, engineers on the Dart team, will present "Putting the App back into Web App - Web programming with Dart". In this session, they will show you how to use Dart to buil…

Extract local variable refactoring now in Dart Editor

Posted by Devon Carew

New Dart Editor build is now available. Highlights from build 7696 include: Extract local variable refactoring!Search and search box fixesIgnore . (hidden) directories for search resultsUpdate #import, #source and #resource references in Dart source during resource rename in Files viewGeneral fixes to the analysis serverAnd in non-editor news: the dart:dom library has been throughly deprecatedRead the full change log or start downloading the Dart Editor from the Editor tutorial.
Thanks for trying Dart!

Notes from 5/14 Dart language meeting

Posted by Bob Nystrom

Once a week, Lars, Gilad, and Kasper meet to discuss the design of the language. For your delight and edification, here are my notes from this week's meeting:
var and Dynamic
We see people using Dynamic as a type argument even when they don't have to. Also see people trying to use var as a type argument. Gilad said there are very few cases where you actually do need to use Dynamic.
The source of the confusion is that var is used in a place (local variable declaration) where you can also use a type to declare a variable, so it makes people think var is itself a type.
He proposed always requiring var to declare variables to clarify that:
  var int foo = 123;
but doesn't think it will be liked.
Alternately, we could follow users' intuition and allow var to be used like a type:
  var map = new Map<int, var>();
Gilad is worried allowing var anywhere a type can appear may have some unpleasant corner cases we aren't thinking of. He likes the curre…

5 items the Dart team has on their radar

Posted by Seth Ladd

Hello Dartisans,

Some of you have asked what the bigger picture is with what we’re working on. The Dart team has the following items on their radar. There is no particular order or priority implied, nor is this exhaustive, but these are some of the features we are either working on or intend to work on.

Across all components we are working improving performance and stability.

Dart language and librariesLanguage see (Area-Language, Milestone-M1)dart:html: parity with the deprecated dart:dom, IndexedDBdart:io: HTTPS, improved HTTP support, optimize performancePackage manager: discover, install, upgrade, version, and publish.Date refactoringContinued work on Future and Isolates APIDart Editorbackground analysis (which will provide a significant speedup)debugging support (browser and VM)simple refactoring support (various rename options to start)search improvements (like text search in libraries)Dart VMdebugging standalone and server programs (from comm…

New Dart Lang Spec tweaks switch statement, abstract methods, and more

Posted by Seth Ladd

We just published version 0.09 of the Dart Language Spec.

Changes include:

Abstract methods may specify default values.Interface methods may specify default values.The ~/ operator can apply to doubles.Refined rules regarding abstract class instantiation, allowing factories to be used.switch statement specification revised.throw may not throw null.Imports introduce a scope separate from the library scope. Multiple libraries may share prefix.Recursive typedefs disallowed.
The switch statement now requires either all the expressions in the cases to evaluate to constant integers or they all evaluate to constant strings. Also, a warning can be generated if you omit the break statement in a case.

As always, the Dart mailing list is standing by to answer your questions, and is a good way to file bugs and feature requests.

New Dart Editor release improves refactoring

Posted by Devon Carew

New Dart Editor build is now available. Highlights from build 7552 include: Improvements to rename refactorings: import prefixes, local functions, getters and setters. Warn when renamed type or member becomes private.Editor compiles both frog and dart2js output in parallel; in a few weeks we'll switch over to solely using dart2js.Fixed external files to open as read-only.Landed sdk text search functionality.Improved text file type filtering (no .dart.js or config dir content).You can read the full change log or download the Dart Editor from the tutorial.

Dart I/O library now uses Future for async

Posted by Mads Ager

We heard your feedback for an easier-to-use I/O library, so we just landed a change to make dart:io use futures for single-shot async methods.

For example, where you used to write:

var f = new File('myfile');
f.onError = (e) => print(e);
f.exists((b) => print('exists: $b'));

you now write:

var f = new File('myfile');
var existsFuture = f.exists();
existsFuture.then((b) => print('exists: $b'));
existsFuture.handleException((e) {
 return true;

This change has multiple advantages:
It is more consistent with the rest of the Dart APIs to use Futures.File and Directory objects are now immutable.Error handling can be done locally per operation instead of having a global error handler and you get the benefit of the error handling mechanisms built into futures.The details are in the code review. We have also updated the Dart I/O API docs.

As always, please share your feedback with us in the Dart mailing list. Thanks for trying Dart!

Learn about Dart in Berlin on May 24

Posted by Seth Ladd

Join Dart engineers in Berlin for a night of Dart on May 24th. The Berlin GTUG is hosting an Introduction to Dart, in partnership with Berlin JS and JUG BB.

From the original announcement:

The two fold event on Thursday, 24th of May, will take place at co-working space AHOY!Berlin in Charlottenburg near Stuttgarter Platz. The first part of the event offers some hands-on Dart experience (from setting up the SDK, IDE, to some “hello world!” accomplishment) and will take place from 4pm to 6pm. Please register at meetup for the first part of the event.  All participants are expected and required to bring their own laptops and power cords. AHOY!Berlin will provide WiFi and 'some' power outlets. The second part will be a presentation about Dart with Q&A (7pm to 9pm) followed by a get together in the Ahoy Lounge where we can continue with a laid-back general discussion about Dart. Please register at meetup for the second part of the event.
Thanks to all the or…

New Dart to JavaScript compiler ready for testing

Posted by Kasper Lund

We're getting close to replacing our old friend "frog"—the current
Dart-to-JavaScript compiler—with a new version called "dart2js". We've
built the new version with an emphasis on correctness and
compatibility with the Dart VM. This means that you can now take
advantage of some of the niceties of closures and code like this:

  main() {
    var closures = [];
    for (var i = 0; i < 8; i++) closures.add(() => i);
    for (var closure in closures) print(closure());

will no longer print 88888888 when compiled to JavaScript, but
01234567 just like on the VM.

The new compiler is available in the latest continuous builds of the
Dart Editor and SDK. If you click on [Tools > Generate JavaScript] in
the editor menu, you'll see that we're automatically compiling your
code with both frog and dart2js allowing you to easily compare the

 Generating JavaScript using frog...
 Wrote ...Sunflower.dart.js [103.0kb written in 1.9 seconds]

Global Dart Hackathon continues with 4 more events this weekend

Posted by Seth Ladd

The Global Dart Hackathon continues this weekend with four more locations around the globe. Join your fellow Dart hackers in London, Indonesia, Tokyo, and Ukraine (both Lviv and Kyiv) as they try Dart, the new structured web programming language. Register today!

The previous hackathons across the globe, including locations such as Israel, India, Brazil, California, Czech Republic, Portugal, Philippines, and Korea, have produced some cool demos. We saw a Redis driver, multi-player games, Android/Chrome mashups, a logic board simulator, and many more. What's most impressive is that these demos were created in only a day or two and with what is still technically a "technology preview" platform.

There will also be participants in the #dart IRC channel on FreeNode if you want to stop by and say hello. We look forward to seeing you at these or future hackathons. As always, thanks for trying Dart!

Dart Team's "Weekly" Digest

Posted by Anders Sandholm
It’s been a while since the last update, but here’s a summary of the recent events in Dart-land. 
First version of the Dart Language Tour is published.
In the Dart language specification, we’ve revised the switch statement specification. There is also an ongoing triage of all open language bugs: classify as either something to be acted on, something that may be considered in the future, or most likely won’t happen.
In the Dart-to-JavaScript Compiler we have: Added rough first version of dart2js to the SDK.Started shrinking the generated code through type-based tree shaking and simplifications of code patterns (much more to come).Changed all bitwise operations to yield 32-bit unsigned results thus making it easier to write algorithms that manipulate bits (crypto, hashing).Added preliminary support for reified generics (work in progress). The Dart Editor now has the following included  Run button launches last run except if application or html file is selectedDeb…