Posts

Showing posts with the label #dartlang

Do This One Thing Or Your Dart Web App Will Break

This is not link bait, this is a serious call to action for our Dartisans. If you do nothing, your Dart web app will stop working in a few weeks. Luckily, the fix is easy. To learn how to keep your Dart web app working, read on! Background Almost all Dart web apps use a small, but crucial, JavaScript file to bootstrap. While strictly not required, this dart.js file contains the necessary logic to turn on the Dart VM, swap out Dart code for JavaScript code if the VM isn't available, enable Dart-JavaScript interop, and more. Most Dart web apps have this line at the bottom of their HTML file: <!-- Don't do this anymore, for illustrative purposes only --> <script src="http://dart.googlecode.com/svn/branches/bleeding_edge/dart/client/dart.js"></script> The Problem There are a few problems with the current arrangement. The Google Code SVN server is not a CDN, and is not optimized for acting as a CDN. Relying on a public HTTP ...

Your First Model Driven View with Dart

Image
Packed inside the Dart Web UI project is inspired by  Model Driven Views (also known as MDV). While Web Components provides encapsulation and reusability, it doesn't say much about linking your data and models with your views. MDV is a set of techniques to help you bind your data to your views , and just like Web Components, you can use Dart with MDV-esque behavior today . Everything you are about to read works across modern browsers, because Dart compiles to JavaScript. The binding. Intro The MDV behavior of Dart Web UI (hereafter referred to as Web UI) helps you bind your data and models to the view in a declarative manner. Binding usually means "when the data changes in one location, change it in another." Typically, web frameworks can wire together the necessary callbacks to keep the view (any text or input fields) in sync with the models (the Dart objects that contain the state of the application). Setup Remember, you'll need a pubspec.yaml...

Dart Up and Running Webcast from O'Reilly

Image
O'Reilly, our publisher for the new Dart Up & Running book by Kathy Walrath and yours truly, ran a webcast to help promote Dart and the book. (If you can't see the embed, you can watch the video directly on YouTube ) This is the first time I used a Hangout for an entire webcast, and I admit the fonts are hard to read in this recording. Good lesson learned for next time! Thanks to everyone who watched, and thanks to Kathy for monitoring the back channel and funneling questions from our viewers.

Your First Web Component with Dart

Image
With all the power we have from HTML5 and the modern web platform, you can't easily do simple things like extend <button>. Luckily, this is changing and the web platform is undergoing a declarative renaissance.  Thanks to the hard work of many groups and individuals across different browser vendors and spec committees, Web Components are emerging as the way to bring structure and encapsulation to modern web developers. The best news yet: you don't need to wait years for these new standards to be implemented, you can use  Dart  to build Web Components today. Web Component basics The component model for the web, aka  Web Components , is a collection of specifications that allow developers to build reusable, encapsulated, and declarative widgets. When people say "Web Components" they generally mean these four ideas: templates , which define chunks of markup that are inert but can be activated for use later decorators , which apply templates to le...

Semantics Matter, 4 Examples in Dart

Image
We recently re-launched the Dart Synonym app, which provides mappings between common Dart/JavaScript/C# patterns, idioms, and snippets. If you know how to build a loop or create a function in JavaScript, this is a great way to learn how to do the same thing in Dart . A great comment on G+ , in response to the re-launch, was "I think Microsoft may have a better idea with TypeScript, which adds a syntax for declaring variable types that should make JavasScript more robust, but it still runs on top of JavaScript, cross browser." While the Dart team welcomes TypeScript to the neighborhood, in the end TypeScript is "just JavaScript". It's great that TypeScript fosters better tooling and bigger web apps, but the same warts of JavaScript are still there with TypeScript. One of the main distinctions between Dart and TypeScript is that Dart cleans up the semantics and not just the syntax . Don't get me wrong, syntax is important, and Dart offers familiar and...

A More Stable Dart M1

Image
Happy Birthday Dart ! Today the Dart project announced the availability of Dart M1 , our first release since the initial technology preview launch almost a year ago. Hurray! To me, Dart M1 is a signal to developers that the project is stabilizing, and we encourage you to start building libraries and projects. The project isn't yet at 1.0, but this new M1 release contains many more platform features and language updates based on feedback we've received from the community. Now is a very good time to try Dart. More stable language The M1 launch signals that the Dart team is more comfortable with the language and is more confident that the days of fast-paced breaking changes are over. Based on feedback from users and the community, the Dart language evolved from its initial release. As Gilad Bracha, the Dart language spec lead, says, "My favorite part was deleting parts out of the spec." In other words, we added features but we also removed features. You can...

9 Dart Myths Debunked

Image
I survived  Addy Osmani's interview and lived to tell the tale. Watch the video below to see Dart myths debunked. Myth 1: Dart is out to replace JavaScript FALSE! Dart provides an option for non-endemic developers to help them be more productive building high-performance apps for the modern web. There are many skilled and productive JavaScript developers, but there are also many many developers familiar with Java, C#, C++, ActionScript, and more. Those developers have certain expectations around their tools and language, and we aim to meet and exceed those expectations. We're building in classes, interfaces, optional static types, lexical scope, optional parameters, generics, and more into the languages. We're building an editor capable of refactoring, quick fixes, static analysis, debugging, and more. Myth 2: It's either Dart OR JavaScript FALSE! Both JavaScript and Dart are technologies that Google believes in and invests in. Google participates i...

final variables in Dart

(Shameless stolen from my own Stack Overflow question and answer .) Dart has a concept of  final . Most dynamic languages don't have this concept. What is final and what do I use it for? final  variables can contain any value, but once assigned, a final variable can't be reassigned to any other value. For example: main() { final msg = 'hello'; msg = 'not allowed'; // **ERROR**, program won't compile } final  can also be used for instance variables in an object. A final field of a class must be set before the constructor body is run. A final field will  not  have an implicit setter created for it, because you can't set a new value on a final variable. class Point { final num x, y; Point(this.x, this.y); } main() { var p = new Point(1, 1); print(p.x); // 1 p.x = 2; // WARNING, no such method } It's important to realize that  final  affects the variable, but not the object pointed to by the variable. That is,  fina...

What Dart Wants

Image
In which a long-time JavaScript community member learns what Dart wants, and is pleasantly surprised. (Note, I'm speaking from my personal perspective in this post.) A reasonable question I received a nice email from Addy Osmani , my friend and colleague in Chrome Developer Relations. Addy is active with the JavaScript community, maintains TodoMVC archive , authors  web development tutorials , and more. It's fair to say that Addy is plugged into modern web development. Beastie Boys, So What Cha Want? (C) 2009 Capitol Records, LLC As a current web developer, Addy was curious about Dart's motivations and philosophy. Is Dart out to replace JavaScript? Who is checking out Dart? What is Dart doing? What does it want ? Luckily, Addy came to the right place. Here's what I wrote back. Choice is good We believe developer choice is good, and options are good. We believe Dart, which can provide a compelling option for modern web app development, ultimately brings ...

Running Dart in the Cloud with Heroku

Image
[EDIT: Updated on 2014-10-11] Dart , the new programming language for modern web apps, certainly compiles to JavaScript. Did you know that Dart also runs on the server as well? Thanks to Heroku's support for third-party runtimes, you can now run your server-side Dart app on Heroku 's cloud. Read on to learn how. (Disclaimer: Even though Heroku can host arbitrary runtimes, they don't officially support the Dart runtime.) Dart for modern web apps Dart is a class based, single inheritance, object-oriented, optionally typed language that is built to help developers of many backgrounds build awesome modern web apps. Most importantly, Dart compiles to JavaScript so that your Dart apps can run all over the web. Dart is familiar to JavaScript, Java, C, C++, and C# developers. There's even bits of Smalltalk in there. While it has a syntax that is instantly recognizable, it also has cool new features like optional static types and isolates . Check out the Dart langua...

Simple Dart + WebSocket demo

[EDIT: Updated on 2013-03-05] I just posted a simple demo of Dart with WebSockets . Not only does it show how to connect to a WebSocket server and send messages, it also shows off a few neat features of the Dart language . (The code follows below, or check out the full  open source project .) Look mom, no classes! Dart is a class-based object oriented language, but that doesn't mean you are required to wrap everything in a class. No sir, this is Dart, not Java. In Dart, you can use top level functions and top level variables. Libraries for modularity Dart organizes code into libraries for modularity. For example, this code uses the dart:html library for the WebSocket code. Concerned about bloat here? Don't be! Thanks to tree-shaking, the code that you don't use is eliminated during a (optional) compile step. The Dart to JavaScript compiler uses tree shaking to help generate minimal JavaScript code (still more work to do here). An upcoming Dart to Dart script wi...

How we built the new Dart homepage

Image
I work with the Dart team, and we needed to update our dartlang.org site. It was a fun project to rebuild dartlang.org , so I wanted to give a shout-out to some of the libraries and tools that we used. The new dartlang.org Requirements for the new dartlang.org included: work on multiple screen sizes display more obvious calls to action load faster clean up CSS display more info on the home page To achieve these goals, we used the following tools: Bootstrap  CSS and widgets Jekyll  (and plugins) site generator Markdown with kramdown  text file formatting Pygments syntax highlighter Compass CSS framework Bootstrap + Compass for SCSS Font Awesome for sprite icons Make build tool optipng image shrinker App Engine hosting Bootstrap , from Twitter, is a slick set of CSS styles and simple JavaScript plugins. Bootstrap has a grid system, pre-defined styles, and most importantly a sane set of defaults for adaptive layouts. Jekyll is a st...

Slides from Dart talk at O'Reilly's FluentConf JavaScript conference

The fine folks at FluentConf included a Dart session in their first JavaScript conference. I had the pleasure of presenting "Structured web programming with Dart", an introduction to Dart's motivations, language, libraries, tools, and ecosystem. The room was packed, which was quite encouraging! I learned that Dart's optional static type annotations are very interesting to JavaScript developers. They especially appreciated the optional part. That is, in Dart you can experiment with simple functions and scripts as you start your idea, and grow over time to full complex modern web apps that use more structure like classes, interfaces, and libraries. Once your design emerges and you are comfortable with the structure, or once you enter maintenance mode, you can add the type annotations. Once those type annotations are in your code, the magic turns on. Type annotations provide inline documentation for your fellow developers. The toolchain can also read the type annot...

My interview with O'Reilly on Dart and doing better.

Image
I had the pleasure of being interviewed by Simon St. Laurent on the topics of Dart and how we can all strive to do better. Thanks Simon! The orignal post has the chapter markers and topics if you want to skip around.

Misleading strong type systems

This post is a record of a Dart Misc mailing list post  titled "Types are useless (?)". The original author was curious why Darts "allows running code with invalid arguments".  My reply follows: --- For reference, let's look at Java. Many would think that Java has a "strong type system" and that its types prevent, as you say, invalid arguments. However, it's easy to write a Java program that will compile just fine, yet fail at runtime. In your words, it will allow running code with invalid arguments. Here's an example: import java.util.*; public class hacked {   public static void test(int i) {     System.out.println(i);   }   public static void main(String[] args) {     String msg = "hacked";     Map cache = new HashMap();     cache.put("hacked", msg);     // later     int hacked = (Integer) cache.get("hacked");     test(hacked);   } } This code will comp...

When Dart types aren't optional

Dart, the structured web programming language, has a feature typically called "optional types". Dart claims that "type annotations don't affect the runtime semantics of the code". This post helps to explain when a type is and isn't optional, and what "type annotation" means as different than "type". The Dart discussion mailing list kicked off a good thread about generics , which evolved into when types can be optional. The Dart community chimed in with great answers (thanks to Ladislav, Sam, John, Dirk, Ross, Bob, and Eli!). Bob Nystrom summed it up well, with some examples that I wanted to specifically highlight: Bob writes: --- Types aren't always annotations. There are type annotations, but there are also places where types appear in code that are not annotations. For example: // type annotations:  int i; foo( int i) => ... class Foo {   int bar;   int baz() => ... }  // types that are not annotation...

Dart Crypto early access

The Dart project just saw its first crypto libraries land , specifically for SHA1 and SHA256. Also appearing is HMAC support. Learn how to use these very new libraries in this post. This new functionality is very new. You'll need to pull the latest from the bleeding_edge branch, as of 2012-04-30. It's so new, it's not even wired into the dart: library scheme, nor is it in the SDK yet. I expect crypto libs to get the full SDK treatment very soon. Here's an example of how to create a SHA256 hash and convert to a hex string: #import('../dart/lib/crypto/crypto.dart'); // Want this in the crypto lib? Star this bug: http://code.google.com/p/dart/issues/detail?id=2839 String digestToString(List<int> digest) {   var buf = new StringBuffer();   for (var part in digest) {     buf.add("${(part < 16) ? "0" : ""}${part.toRadixString(16).toLowerCase()}");   }   return buf.toString(); } main() {   var sha = new SHA256()...