Saturday, September 29, 2012

Breaking Change: Hashable interface is removed

Lasse Nielson writes to the Dart mailing list:

Now that we have implemented hashCode on Object, we no longer need the Hashable interface for anything.
We have removed all references to Hashable in the SDK classes[1], and will be removing the Hashable interface
itself later - no earlier than in two weeks, but at some later point it will be removed without further warning.

The Hashable interface is still there, so classes that implement Hashable won't break immediately.
Code that *tests* whether an object is Hashable will probably begin failing immediately! For example String is no longer Hashable.

Two Dart M1 language changes converged to make this breaking change possible. First, explicit interfaces have been removed. Dart classes expose an implicit interface, so no need for explicit interface declarations. Second, Object now implements hashCode, so all objects explicitly are hashable.

As always, you can join the discussion at that Dart mailing list, or ask questions on Stack Overflow. Thanks for trying Dart!

Wednesday, September 26, 2012

Breaking Change: Raw string syntax

Matthias Hausner wrote to the Dart mailing list about an upcoming break change. Matthias writes:


Tomorrow Thursday 9/27 we will eliminate support for the old raw string syntax that uses the @ prefix. The new syntax requires an r instead of the @ in front of the raw string literal.

@"..."  ->  r"..."
@'...' -> r'...'
@"""..."""  ->  r"""..."""
@'''...'''  ->  r'''...'''

The Dart Editor (build 12784) can perform this change automatically.


Time to update your code!

Use JavaScript code in your Dart apps

You can now use existing JavaScript code with Dart! We've recently released a JavaScript-Dart interop library, one of our developers' most requested features. This is a big milestone for the Dart project.

Using this library, you can proxy JavaScript objects inside Dart code. You can also reach Dart functions from JavaScript code.

Here's an example of wrapping a Google Maps API object:


var canvas = query('#map_canvas');
var googlemaps = js.context.google.maps;
var googlemap = new js.Proxy(googlemaps.Map, canvas);



This code instantiates a JavaScript google.maps.Map object onto the given canvas and returns a proxy to Dart. Note that googlemaps.Map is a proxy to the JavaScript constructor. The resulting googlemap is a proxy to the actual Google Map object in JavaScript.

Here's an example of calling a Dart function from JavaScript:


js.context.handler = new js.Callback.once(display);



var script = new ScriptElement();
script.src
 = 'http://search.twitter.com/search.json?q=dartlang&rpp=10&callback=handler';
document.body.nodes.add(script);



You can read more about using existing JavaScript code inside your Dart apps. As always, please join the discussion at the Dart mailing list or on Stack Overflow. Thanks for trying Dart!

Dart + HTML5 = Happy Web Developers

If you’ve been using HTML5 for a while, you’ve probably seen HTML5 Rocks. However, it’s not always clear how to translate these samples into Dart. To fix this, we’ve started a new project called dart-html5-samples, where we’ve started porting the HTML5 Rocks samples.

We’ve already ported a bunch of tutorials such as:

Along the way, we’ve occasionally encountered bugs in Dart. By filing these bugs on dartbug.com, we’ve not only been transparent about the process, but we've given the community a chance to vote for the features they find important.

Although we’ve ported a lot of samples, many more remain. If you’d like to help out, this would be a great way to contribute to the Dart project! Just fork the project on GitHub, and send us a pull request. Make sure you submit a bug in the issue tracker with the tutorial you plan on porting, so that others will know you are working on it. Finally, make sure to take a look at the other examples to get a feel for how we’ve structured things.

As always, if you’d like to chat more about this, feel free to send us email on the mailing list or ask questions on Stack Overflow.

Happy Hacking!
Shannon -jj Behrens and Jason Brooks

Tuesday, September 25, 2012

Pub support in Editor

A new Dart Editor build is available at www.dartlang.org/editor. Changes include:



Pub support in now on in the integration build! Features include:
  • analysis support for the packages directories
  • a pubspec.yaml editor, with syntax highlighting and other goodies
  • our new app wizard can optionally create your app in a pub friendly format, including a sample pubspec.yaml file
  • the 'pub install' and 'pub update' tools are available from the Tools menu
  • the open folder dialog will run 'pub install' automatically if there is a pubspec.yaml
In addition:


  • The Eclipse plugins distro is now compatible with Eclipse 4.2.
  • We now support using @override and @deprecated metadata from package:meta/meta.dart. See this CL for an example.
  • Our syntax and semantic highlighting has been dialed back a bit.
  • Added a clean up to migrate raw strings from @'str' to r'str'.
  • Added a clean up to migrate parseInt() and parseDouble() references to int.parse() and double.parse().
  • Added a clean up for converting "===" to "==" and "identical()", and for converting "!==" to "!=" and "!identical()".
  • The debugger now shows hashmap contents as their symbolic key:value pairs, instead of showing the internal fields of the HashMapImplementation class.
  • Miscellaneous fixes to our plugins distribution, fixes to our cleanups, and 15 analysis fixes.
If you downloaded last week's integration build, try updating with the auto-update feature (Preferences > Update). And as always, view the changelog for the full list of changes, and to get started with the Editor see our tutorial.

Monday, September 24, 2012

3 Dart events at GOTO Conference


Next week, Dart is going to be at the GOTO Conference in Aarhus, Denmark! We have three Dart events this year.


After an introduction to the language, we'll guide you through all the steps to create your first Dart application. The code lab was battle tested in June during Google I/O, and is ready to go. We'll lead you through the process of building a modern web app with the Dart platform, using both client-side and server-side Dart. You will explore the language, libraries, editor, and integration with Chromium. You'll leave this session with a working Dart app that works in modern browsers. Register now!


To make Dart run in all modern browsers, we have implemented an optimizing Dart-to-JavaScript compiler. Performance-wise the biggest challenge is the gap between the semantics of Dart's low-level operators and JavaScript's builtin primitives. This presentation will introduce you to the Dart language and the deployment options before diving into the details of the intermediate representation and the implemented optimizations.


Dart Editor is a lightweight, open-source editor for writing Dart applications. I will demonstrate how the editor helps you efficiently write modern web apps with Dart. After creating a Dart application we'll quickly navigate and search through Dart source, and accurately write code with refactoring and code completion tools. You'll also see how the editor connects to Dartium (Chromium with the Dart VM) for a fast development and debugging experience.

We look forward to meeting you and listening to your feedback. Hope to see you at GOTO!

Thursday, September 20, 2012

Dart Language meeting notes from Sept 17

Bob Nystrom posted the latest Dart language meeting notes to the mailing list. Bob writes:


Here's my notes from this weeks meeting:

0.11 language spec

I asked when we'd be publishing the next version of the language spec. Gilad says "real soon now". We keep making changes so we don't want to publish just to immediately invalidate something a few days later.

scope of type parameters

Gilad brought up what happens if you try to access a type parameter within a static method:

class Foo<T> {
  static bar() => T; // <- What does this mean?
}

Currently they are just not in scope, which means it could refer to some other outer name.

Instead, maybe we should say they are in scope, but you can't use them, which is consistent with other names inside a class.

Kasper says there one's scope. It doesn't matter whether you are on the instance or static side. You'll just get an error if you try to refer to something from the wrong side.

warnings on built-in identifiers

Gilad wonders if the warnings aren't helpful for things like "get" and "set" even though they are allowed. We discussed not showing a full warning but maybe some sort of "suggestion" that you shouldn't do that. We've decided to drop the warnings.

limited stack traces

The language spec was changed recently to state that when you get a stack trace in a catch, it only includes the stack frames from between the throw and the catch, but nothing past that. This means users can't get the full context for how an exception was reached.

Lars said the intent was can look at the catch handlers on the stack to see if you need to collect stack trace at all. We never intended it to be partial stack trace. The semantics were always intended to be entire stack trace.

Gilad will update the spec.

cascaded calls in initializer expressions

Right now, you have to parenthesize them, and we're not sure why. Gilad will look into the grammar and see if it doesn't work out.

lowercase string

Kasper said early on they discussed aliases for things like Integer -> int. But then they figured people would use a mishmash of both, which would be ugly and inconsistent. Instead, they chose to go with a single name for each built in type.

Lars said they looked at the built-in types and picked a list of them that they felt should have easier lowercase names. They didn't want all of them, so they had to draw the line somewhere. They are happy with "String" as it is.

Cheers!

Wednesday, September 19, 2012

Dart helps you build Web Components today

Watch this episode of Dartisans and learn more about using Dart with Web Components. Even though Web Components aren't yet baked into the platform, you can use Dart to build Web Components today and compile them down into code that works in modern browsers.


You can follow along with the open-source dart-web-components work on Github.

With Dart, you can build structured web apps. With Web Components, you can build encapsulated, declarative components. Two great ideas that go together!

Dart Team Updates, Sep 5 - 18, 2012

Summary
  • Dart is getting closer to reaching Milestone 1. We have been doing a lot of M1 bug-fixing across sub components. There is now a Dart web components sample available. We have a new pub package layout and the editor now comes with the possibility to auto-update.

Details

Dart Editor:
  • Lots of SDK changes: dart:dom was removed and several libraries moved from dart-sdk/lib to dart-sdk/pkg.
  • Run the Dartdoc tool from the Editor - see Tools > Generate Dartdoc.
  • Code completion now supports the method cascades syntax (foo..and()..another()..thing()).
  • New clean up to convert old optional parameters to the new optional named ones where possible.
  • New refactoring to convert optional positional parameters to named.
  • New "Convert Method to Getter" refactoring.
  • Rename refactoring improvements - if there are potential references to a field or method, we will warn the user and display a preview dialog.
  • New Quick Fix to create a library import for unresolved functions and fields.
  • No longer report 'no such method' warnings if class defines 'noSuchMethod()'.
  • Warnings created for inferred types are now displayed only in the source itself - See them in the Problems view by toggling the 'show informational messages' button.
  • Using the old catch syntax is now an error.
  • Files view now displays whether a dart: library is client only (like dart:html) or server only (like dart:io).
  • New preference to enable code folding.
  • Fixed an issue where our search box would not consistently show SDK types.
  • Fix for a crash related to the break-on-exceptions feature, and for a crash that could occurred when launching Dartium with breakpoints set.
  • Various analysis fixes, debugger UX improvements, and performance improvements for large projects.

Dart UI [dart:html, web components]:

Dart SDK and build:
  • lib/ directory split into lib/ and pkg/ . In the SDK, lib/ and dart: are now identical.

Pub:
  • Integrate bootstrap into pub.dartlang.org and give it a basic look and feel
  • Show description, authors, and homepage on package pages
  • Integrate docs into pub.dartlang.org
  • Work on launch process for pub.dartlang.org: talk to pcounsel, create launch, write design doc and privacy design doc, etc.
  • Change package layout, and update pub, explain to the list, update our packages, and update the docs

Dart Server [dart:io, etc.]:
  • Lots of M1 bugfixing.

Dart Dev Rel

Tuesday, September 18, 2012

Breaking Change: parseInt to become int.parse

Yesterday, Lasse Nielsen, an engineer on the Dart team, wrote to the Dart mailing list about a new breaking change coming to the Dart core libraries. The parseInt and parseDouble from dart:math will be replaced by int.parse and double.parse, respectively.

Lasse writes:

Greetings all.

We are removing parseInt and parseDouble from the dart:math library, and making them static methods called "parse" on the int and double classes.
The original reason, from long ago, for putting them in Math was that int and double were interfaces, and couldn't contain static methods. Now that we are converting all interfaces to abstract classes, we will move those functions where they belong.

The dart:math parseInt/parseDouble functions will still work, but they will be removed in about a week.

The functions now have documentation too! Please do report if it is confusing or misleading in any way.

Cheers
/L


A good discussion then followed with suggestions for creating named constructors, or if parse should be moved to num. You can follow along at the Dart mailing list for more. Thanks for trying Dart!

Monday, September 17, 2012

Dart Editor gets auto-update!


A new Dart Editor build is available at www.dartlang.org/editor. Changes include:

The last Editor you'll ever download! We now support auto-updating the editor. This was one of our most starred issues. To try it out, open the Preferences dialog and enable auto-updating.



Additional release notes:
  • You can now run the Dartdoc tool from the Editor - see Tools > Generate Dartdoc.
  • There's a new clean up to convert old optional parameters to the new optional named ones where possible.
  • There's a new refactoring to convert optional positional parameters to named.
  • The Files view now displays whether a dart: library is client only (like dart:html) or server only (like dart:io).
  • Added a preference to enable code folding.
  • Several performance improvements for large projects.
  • Fix for missing keystrokes in the searchbox (on GTK Linux).
  • Fix for a crash related to the break-on-exceptions feature, and for a crash that could occurred when launching Dartium with breakpoints set.
  • 10 analysis issues fixed.
And one more thing - Pub support is now in continuous! This is just baked in and still undergoing testing. For those who like to live dangerously, you can get your fresh baked Pub support hereAs always, view the changelog for the full list of changes, and to get started with the Editor see our tutorial.

Friday, September 14, 2012

Simplify your constructors and top-level variables

The Dart mailing list was treated to some very good news today. Kasper Lund informed us that lazy init of statics and top-level variables is ready for use!

Kasper writes:

We now have one of the major new language features of M1 implemented
across the board. That's right -- you can now use lazy initialization
for top-level and static variables (both final and non-final). This
means that the restriction that used to force the initialization
expression for such a variable to be a compile-time constant is no
more. You can now write:

// Top-level.

final worklist = new Queue();
var compiler = new Compiler(worklist);

main() {
  compiler.compile();
}
and both worklist and compiler will be initialized on first access.

We've also lifted the restriction for instance fields so the following
code now runs just fine:

class Cache {
  final Map table = new Map();
  Logger log = new Logger();
  ...
}


as long as the initialization expressions do not refer to [this]. Such
expressions are evaluated when the object is created (not lazily on
first access as we do for static and top-level variables), but it cuts
down on the need for lengthy initializer lists in your constructors.

As always, you can join the Dart mailing list or ask questions on Stack Overflow.

Thursday, September 13, 2012

Breaking change: Remove '.dynamic' from Object

Today, Dart engineer Lasse Nielsen informed the mailing list that Dynamic will be renamed to dynamic. He writes:

We will be renaming the "Dynamic" type to "dynamic", and as the first step we will remove 'dynamic' as a getter on Object in a few days. 

Code that uses "x.dynamic" can be rewritten to use the equivalent "(x as Dynamic)". 

As you might know, dynamic (as it is now called) is the stand-in type when a static type annotation is not provided.

I asked Lasse for some background on this change. He continued: "One positive thing is that all built-in identifiers and keywords are now all lower-case. It's a special type, like 'void', and not a class, so consistency might also be a point."

As always, we invite you to join the discussion on the Dart mailing list, and ask questions at Stack Overflow.

BREAKING CHANGES: Duration, RegExp, Uri.fromComponents

Kasper Lund has been making good use of the new named optional parameters syntax, a new Dart M1 language feature. He writes to the mailing list:

Over the last few days, I've changed the constructors for Duration,
RegExp, and Uri.fromComponents to insist on getting their optional
parameters passed by name. This is possible using the new named
optional parameter syntax where the formal parameters are enclosed in
{ }:

  class RegExp ... {
    const RegExp(String pattern, {bool multiLine, bool ignoreCase});
  }


It isn't possible to pass these optional parameters positionally
anymore; you have to pass them by name or leave them out:

  const RegExp("foo")
  const RegExp("foo", multiLine: true)
  const RegExp("foo", ignoreCase: false)
  const RegExp("foo", multiLine: true, ignoreCase: false)


The following constructor invocation that used to be legal are now illegal:

  const RegExp("foo", true)
  const RegExp("foo", true, false)

Wednesday, September 12, 2012

New pub package layout

Today, Bob Nystrom, one of the pub engineers, posted details about the new pub package layout. Time to use the new layout for your packages!

Bob writes:


If you live on bleeding_edge, pub now supports the new package layout conventions that avoid the nasty circular symlinks.

Pub also still supports the old style too, simultaneously. It works like this:
  1. When pub is generating a symlink to a package it determines if it's an old style or new style package. The presence of a .dart file at the top level (aside from build.dart) indicates that it's an old style package.
  2. If it's an old style package, pub symlinks to the package's root directory.
  3. If it's a new style package, it looks for a "lib" directory inside that package and symlinks to that.
  4. It will also generate a self link, but only for new style packages.
So, if you have:

myapp/
  pubspec.yaml -> depends on old_style and new_style
  lib/
    app.dart

old_style/
  old_style.dart

new_style/
  lib/
    new_style.dart

You run "pub install" on myapp, and you'll get:

myapp/
  pubspec.yaml -> depends on old_style and new_style
  lib/
    app.dart
  packages/
    myapp/ -> symlink to myapp/lib/
      app.dart
    old_style/ -> symlink to old_style/
      old_style.dart
    new_style/ -> symlink to new_style/lib/
      new_style.dart

Note that inside packages/ everything looks like you want and your imports should be unchanged. What this means is that if some package you depend on migrates from the old to the new style, it's shouldn't affect you. The next time you update that package, it will magically do the right thing.

All of the SDK packages that come with Dart are still using the old style, but we'll be updating those over the next couple of weeks. Around M1, I will remove support for the old layout. If you haven't updated your package by then, it will stop working.

Let me know if you have questions/comments/complaints/sonnets. You can read more about the pub package layout recommendation.


As always, you can join the discussion at the Dart mailing list, and post questions to Stack Overflow.

Change final to const for top-level and static variables now

Kasper Lund, engineer on the Dart project, sent a notice of a new breaking change to the Dart mailing list today.

Kasper writes:


TL;DR: Change final to const for top-level and static variables now.

Over the next days, we will stop treating references to top-level or
static final variables as compile time constant expressions. This
means that the following code will be illegal:

   final X = 42;
   final Y = const [ X ];

because you can only build constant lists out of compile time
constants. The fix is easy. Just replace final with const and you'll
be good to go (this works today):

   const X = 42;
   const Y = const [ X ];

The nice thing is that this paves the way for lazy static
initialization which allow you to initialize top-level and static
(final) variables with non-constant expressions like this:

   final Z = new Set<int>();

Note that this isn't supported across all our platforms just yet.

As always, you can join the discussion at the Dart mailing list, and ask questions at Stack Overflow.

Learn About Compiling Dart to JavaScript

Dart runs across the modern web, thanks to our Dart to JavaScript compiler. We recently sat down with some engineers from the dart2js project. Enjoy the video!


Don't forget to watch our past episodes of Dartisans!

Tuesday, September 11, 2012

Negate() changes to -() soon

Today, Kasper Lund gave dartisans a head's up about an upcoming breaking change. Kasper writes:

We're getting rid of operator negate in favor of the unary operator -. 
If you have code like this: 

   operator negate() => ... 

now would be a great time to change that to: 

   operator -() => ... 

I expect that we will turn off the support for negate within a few days.

Why make this change? We didn't want developers to see negate() and think they can actually call object.negate(). We hope -() makes it more obvious.

As always, you can join the discussion at the Dart mailing list or ask questions on Stack Overflow. Thanks for trying Dart!

Monday, September 10, 2012

Editor can now convert methods to getters

A new Dart Editor build is available at www.dartlang.org/editor. Changes include:
  • Lots of SDK changes: dart:dom was removed and several libraries moved from dart-sdk/lib to dart-sdk/pkg.
  • During a rename refactoring, if there are potential references to a field or method, we will warn the user and display a preview dialog.
  • Using the old catch syntax is now an error.
  • We have a new "Convert Method to Getter" refactoring.


  • We no longer report 'no such method' warnings if class defines 'noSuchMethod()'.
  • We added a Quick Fix to create a library import for unresolved functions and fields.
  • The warnings we create for inferred types are now displayed differently from other errors. You can view them by hitting the 'show informational messages' button in the Problems view.
  • Fixed an issue where our search box would not consistently show SDK types.
  • Several miscellaneous debugger UX improvements, and 11 analysis issues fixed.
As always, view the changelog for the full list of changes, and to get started with the Editor see our tutorial.

Friday, September 7, 2012

Dart Language Nears M1 State

Posted by Seth Ladd

Dart Team Updates - August 18-Sept 4th


Learn more at http://dartlang.org

Summary
  • The language spec is nearing its M1 state, the core libraries have been unified, the VM and dart2js implement more M1 features, and the editor improves on static analysis, refactorings, and quick fixes.

Details

Dart language specification:
  • 0.11 spec nearing completion: all M1 features covered.

Dart libraries [core, unittest, i18n, etc]:
  • The core and coreimpl libraries have been unified across dart2js and the VM. There are still implementation-dependent sources, but there is only one corelib and the SDK only contains implementation-independent files.

Dart VM:
  • New compiler: Deoptimization support, class hierarchy analysis, unboxing of doubles in select instructions, smi and class check elimination, stackmaps for live registers and simple inlining.
  • Language features: Argument definition test (aka '?' prefix operator), abstract class handling, disabled legacy try-catch.
  • Started removal of explicit interfaces in core library code, added Expando implementation.
  • Tuned performance of string operations and native calls.
  • Working down the queue of security fixes.
  • Resolved a few stability issues caused by missing store barriers.

Dart to JavaScript Compiler:
  • Language features: Added support for annotations (metadata), enabled calling non-functions through the call method, removed #resource directive.
  • Re-triaged all bugs so we have a clearer picture on what goes into the M1 release.

Dart Editor:
  • M1 language migration wizard: Right click on your project and choose 'Clean up...'. We've implemented cleanups for catch blocks, the new getter syntax, operator equals, and library/import/source changes.
  • Dart syntax highlighting in the compare and refactoring dialogs.
  • Dart Editor build hook. If a build.dart script exists in a project, we'll invoke it as part of the Editor's build process. This allows for custom processing of changed resources, like for templating systems, generating Dart code, or scss --> css processing. There are sample scripts available at dart/samples/buildhook1 and dart/samples/buildhook2, as well as online at https://github.com/dart-lang/dart-web-components/blob/master/build.dart.
  • Our type inference engine has been enhanced to add support for inferring types from dart:html select().
  • The type inference engine now handles the case where a variable is assigned different types at different times, and will show you the intersection of legal method and field references. In addition we now infer the type of List and Map literals.
  • Added basic scss (http://sass-lang.com/) syntax highlighting.
  • dart:mirrors has been added to the SDK; the editor can now resolve the mirrors library and the types within it.
  • Added warnings for use of obsolete getter and catch syntaxes.
  • We now highlight single line /// dartdoc comments.
  • We now do a better job of displaying when the debugger halts at an uncaught exception.
  • The Editor workspace location has changed. The workspace is where we store information about your open files and folders. We had stored this in a 'workspace' directory co-located with the Editor application. We now always locate it in the user's home directory. The first time you run this new build you'll have to re-open the folders you had been working on. For more info, see http://www.dartlang.org/docs/editor/#settings.
  • Several libraries have moved from dart-sdk/lib to dart-sdk/pkg. This means that they will not show up in the Files view and will no longer be accessible (erroneously) as a dart: import. You'll want to use pub to access these pkg libraries.
  • 17 analysis issues fixed, as well as ongoing changes to support the M1 language.
  • General fixes and enhancements to the rename refactoring, code completion, the extract variable refactoring, hyperlinking, searchbox UX, and the debugger UX.

Dart UI [dart:html, web components]:
  • XMLHttpRequest is now HttpRequest. Because seriously, when is the last time you sent XML over XMLHttpRequest? :)

Dart SDK and build:
  • SDK no longer contains VM-specific files for core and coreimpl libraries.

Pub:
  • Lots of bug fixing (7 issues fixed, more merged or re-routed).
  • More pub documentation.
  • Move some internal packages (args, yaml, etc.) over to pub.dartlang.org.
  • Dogfood pub.dartlang.org with Dart team.

Dart Server [dart:io, etc.]:
  • Bug fixes.
  • Work in progress on HTTPS support.

Dev Rel:
    • Updating Language Tour and book to M1