Dart a modern web language

Similar documents
Language Based Virtual Machines... or why speed matters. by Lars Bak, Google Inc

Modern Web Development with Dart. Alan Knight Google

JavaScript as a compilation target Making it fast

The V8 JavaScript Engine

Glossary of Object Oriented Terms

Overview. Elements of Programming Languages. Advanced constructs. Motivating inner class example

Crash Course in Java

e ag u g an L g ter lvin v E ram Neal G g ro va P Ja

Comp 411 Principles of Programming Languages Lecture 34 Semantics of OO Languages. Corky Cartwright Swarat Chaudhuri November 30, 20111

Mobile Web Design with HTML5, CSS3, JavaScript and JQuery Mobile Training BSP-2256 Length: 5 days Price: $ 2,895.00

C Compiler Targeting the Java Virtual Machine

Programming Languages Featherweight Java David Walker

Art of Code Front-end Web Development Training Program

Java 6 'th. Concepts INTERNATIONAL STUDENT VERSION. edition

core. Volume I - Fundamentals Seventh Edition Sun Microsystems Press A Prentice Hall Title ULB Darmstadt

Upgrade to Microsoft Web Applications

JavaScript. JavaScript: fundamentals, concepts, object model. Document Object Model. The Web Page. The window object (1/2) The document object

Scoping (Readings 7.1,7.4,7.6) Parameter passing methods (7.5) Building symbol tables (7.6)

C# and Other Languages

CSC 551: Web Programming. Spring 2004

Android Application Development Course Program

Fast JavaScript in V8. The V8 JavaScript Engine. ...well almost all boats. Never use with. Never use with part 2.

Semantic Analysis: Types and Type Checking

Introducing Apache Pivot. Greg Brown, Todd Volkert 6/10/2010

CSE 373: Data Structure & Algorithms Lecture 25: Programming Languages. Nicki Dell Spring 2014

Java Interview Questions and Answers

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives

Computer Programming I

Pattern Insight Clone Detection

Tachyon: a Meta-circular Optimizing JavaScript Virtual Machine

Programming in HTML5 with JavaScript and CSS3

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

CS 51 Intro to CS. Art Lee. September 2, 2014

Course MS10975A Introduction to Programming. Length: 5 Days

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

To Java SE 8, and Beyond (Plan B)

Kotlin for Android Developers

Java CPD (I) Frans Coenen Department of Computer Science

The Sun Certified Associate for the Java Platform, Standard Edition, Exam Version 1.0

Progressive Enhancement With GQuery and GWT. Ray Cromwell

Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007

J a v a Quiz (Unit 3, Test 0 Practice)

CSCI 3136 Principles of Programming Languages

Functional Programming

1/20/2016 INTRODUCTION

Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following:

Power Tools for Pivotal Tracker

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

HybriDroid: Analysis Framework for Android Hybrid Applications

White Paper. The Power of Siebel escripting at Runtime. Bringing Siebel Developer Closer to Rapid Application Development

Fundamentals of Java Programming

AP Computer Science Java Subset

Lecture 9. Semantic Analysis Scoping and Symbol Table

<Insert Picture Here> What's New in NetBeans IDE 7.2

Java EE Web Development Course Program

Programming Languages CIS 443

CSC230 Getting Starting in C. Tyler Bletsch

Programming Languages

No no-argument constructor. No default constructor found

Programming Project 1: Lexical Analyzer (Scanner)

Moving from CS 61A Scheme to CS 61B Java

Computing Concepts with Java Essentials

The Java Series. Java Essentials I What is Java? Basic Language Constructs. Java Essentials I. What is Java?. Basic Language Constructs Slide 1

Pluggable Type Systems. Gilad Bracha

Web development... the server side (of the force)

Google Web Toolkit. Introduction to GWT Development. Ilkka Rinne & Sampo Savolainen / Spatineo Oy

Visual Basic. murach's TRAINING & REFERENCE

CS-XXX: Graduate Programming Languages. Lecture 25 Multiple Inheritance and Interfaces. Dan Grossman 2012

1. Overview of the Java Language

EMSCRIPTEN - COMPILING LLVM BITCODE TO JAVASCRIPT (?!)

TypeScript. Language Specification. Version 1.4

McGraw-Hill The McGraw-Hill Companies, Inc.,

Introduction to Programming System Design. CSCI 455x (4 Units)

Java SE 7 Programming

Chapter 13: Program Development and Programming Languages

Parrot in a Nutshell. Dan Sugalski dan@sidhe.org. Parrot in a nutshell 1

The C Programming Language course syllabus associate level

TypeScript for C# developers. Making JavaScript manageable

Evolution of the Major Programming Languages

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

Lecture 1 Introduction to Android

Introduction to Android

RARITAN VALLEY COMMUNITY COLLEGE ACADEMIC COURSE OUTLINE. CISY 105 Foundations of Computer Science

Master of Sciences in Informatics Engineering Programming Paradigms 2005/2006. Final Examination. January 24 th, 2006

Rakudo Perl 6 on the JVM. Jonathan Worthington

Dart and Web Components - Scalable, Structured Web Apps

The programming language C. sws1 1

Interpreters and virtual machines. Interpreters. Interpreters. Why interpreters? Tree-based interpreters. Text-based interpreters

Java SE 8 Programming

CS 111 Classes I 1. Software Organization View to this point:

Chapter 1 Java Program Design and Development

Tutorial on Writing Modular Programs in Scala

QML and JavaScript for Native App Development

CSCI E 98: Managed Environments for the Execution of Programs

Chapter 1. Dr. Chris Irwin Davis Phone: (972) Office: ECSS CS-4337 Organization of Programming Languages

Visualizing Information Flow through C Programs

Chapter 12 Programming Concepts and Languages

Language Evaluation Criteria. Evaluation Criteria: Readability. Evaluation Criteria: Writability. ICOM 4036 Programming Languages

Transcription:

Dart a modern web language or why web programmers need more structure Kasper Lund & Lars Bak Software engineers, Google Inc.

Object-oriented language experience: 26 + 12 years

The Web Is Fantastic The web is everywhere Developing small applications is easy No required installation of applications Support for incremental development Friendly competition drives the industry

The Web Platform Wheel of Improvements New browser features in ps Ap Pe n rfo rm an ce io at ov n In

JavaScript Performance Improvements V8 Benchmark Suite v3 - higher numbers are better

Challenges for the Web Programmer productivity Application scalability Raw execution speed Startup performance... if we don't innovate, the web will lose to mobile apps

Welcome to the Dart Platform A web programming platform that has accepted these challenges High level goals Simple productive programming language Support for programming in the large Predictable high performance Ultra-fast startup Compatibility with modern browsers

Fundamental JavaScript Issues JavaScript is everywhere, but it isn't necessarily the right tool for every job

JavaScript Issue #1: Where Is The Program? JavaScript code is hard to reason about Almost no declarative syntax Borderline impossible to find dependencies Monkey patching makes it even worse Understanding the program structure is crucial Easier code maintenance and refactoring Better debuggability and navigation of code

Where Is The Program? All declarations are actually statements that must be executed JavaScript function Point(x, y) { this.x = x; this.y = y; } Fields are "declared" implicitly by the statements in the constructor.

Where Is The Program? It can be pretty hard to analyze what actually gets declared JavaScript function Point(x, y) { if (Object.defineProperty) { Object.defineProperty(this, 'x', { value: x, writable: false }); Object.defineProperty(this, 'y', { value: y, writable: false }); } else { this.x = x; this.y = y; Control flow makes it difficult to statically } tell which fields you end up with }

JavaScript Issue #2: Keep On Truckin' JavaScript has a keep on truckin' mentality Mistakes are tolerated Wrong types lead to unusable results Almost anything goes... Throwing errors eagerly is better Easier to locate the source of errors Forces more errors during testing Gives confidence in deployed apps

Keep On Truckin': Constructors Are Just Functions Seems nice and simple, but leads to lots of issues JavaScript function Point(x, y) { this.x = x; this.y = y; } var point = Point(2, 3); assert(point == undefined); assert(x == 2 && y == 3); // Whoops, forgot to write new but // that's okay because we get undefined back // and now we have more global variables!

Keep On Truckin': Accessing Non-existing Properties Typos lead to code that runs but does that wrong thing JavaScript var request = new XMLHttpRequest();... request.onreadystatechange = function() { if (request.readystate == 4) { console.log('request done: ' + request.responsetext); } };

Keep On Truckin': Accessing Non-existing Properties Typos lead to code that runs but does that wrong thing JavaScript var request = new XMLHttpRequest();... request.onreadystatechange = function() { if (request.readystate == 4) { console.log('request done: ' + request.responsetext); } }; Did you mean: readystate?

Keep On Truckin': Implicit Conversions Mixing objects and immutable values var string = 'the quick brown fox'; string.hash = md5(string); assert(string.hash == undefined); JavaScript // strings are values, not objects // string -> object // string -> object (a different one)

Keep On Truckin': Implicit Conversions This just gets worse and worse JavaScript true but why? true but why? true but why? assert(2.0 == '2' == new Boolean(true) == '1'); Enough implicit conversions to make your head explode?

JavaScript Issue #3: Unpredictable Performance Advice: Use the efficient subset of JavaScript VMs have been optimized for certain patterns Benefit from the performance improvements Harder than it sounds Lots of differences between browsers Not just about syntactic constructs JavaScript performance is very unpredictable Building high-performance web apps in JavaScript is tricky JavaScript Efficient JavaScript

Summary of JavaScript Issues Program structure is hard to find, understand, and reason about Monkey patching core objects does not make it any easier Keep on truckin' mentality hides bugs and limits productivity Performance is unpredictable and really bad for application startup We believe innovation is needed to improve productivity of web developers

The Dart Programming Language In a nutshell

Dart in a Nutshell Unsurprising simple object-oriented programming language Class-based single inheritance with interfaces Familiar syntax with proper lexical scoping Single-threaded with isolate-based concurrency Optional static types Syntax JavaScript Dart = Objects Smalltalk Types Strongtalk Isolates Erlang Concepts C#

First Dart Example Point example that computes distance to origin Dart class Point { var x, y; Point(this.x, this.y); operator +(other) => new Point(x + other.x, y + other.y); tostring() => "($x,$y)"; } main() { var p = new Point(2, 3); print(p + new Point(4, 5)); }

Optional Static Types Static type annotations convey the intent of the programmer They act as checkable documentation for code and interfaces They can be generic which makes them very useful for collections They have no effect on runtime semantics The Dart type system is considered unsound since downcasts are allowed However, these downcasts can be validated at runtime

First Dart Example Now with static types Dart class Point { num x, y; Point(this.x, this.y); Point operator +(Point other) => new Point(x + other.x, y + other.y); String tostring() => "($x,$y)"; } main() { Point p = new Point(2, 3); print(p + new Point(4, 5)); }

Dart Has Covariant Generic Types An apple is a fruit, so a list of apples is clearly a list of fruits? Dart main() { List<Apple> apples = tree.pickapples(); printfruits(apples); } void printfruits(list<fruit> fruits) { for (Fruit each in fruits) print(each); }

Demo: Runtime Type Checking In Dart It's demo time...

Potpourri of Cool Dart Language Features

Named Constructors No overloading based on argument types Dart class Point { var x, y; Point(this.x, this.y); Point.polar(r, t) : x = r * cos(t), y = r * sin(t); } main() { var p = new Point(2, 3); var q = new Point.polar(3, 0.21); }

Interfaces With Default Implementations Instances can be constructed from interfaces Dart interface List<E> implements Collection<E> default ListFactory<E> { List([int length]);... } main() { var untyped = new List(); var typed = new List<Point>(12); } // any object can be added // only points can be added

Cascaded Calls Multiple calls to the same object Dart void drawcircle(canvaselement canvas, int x, int y, int size) { canvas.context..beginpath()..arc(x, y, size, 0, Math.PI * 2, false)..fill()..closepath()..stroke(); }

Proper Capturing of Loop Variables Prints 01234567 rather than 88888888 as in JavaScript Dart main() { var closures = []; for (var i = 0; i < 8; i++) closures.add(() => i); for (var c in closures) print(c()); } For each iteration of the loop, a fresh copy of the variable i is captured. // collect // evaluate

Dart Is Beautiful Dart programs are declared and easy to read in the source code Clean semantics without surprises No strange implicit conversions are performed Libraries cannot be monkey patched at runtime Java, C#, and JavaScript programmers: You can be productive in Dart within a few hours

The Dart Project Greater than the sum of its parts

The Language Is Only a Part of the Story Making Dart great for web development depends on entire platform Developers also need: Fast execution and startup Tools for development and code analysis Great integration with the DOM

Deployment and Execution Application source code + Libraries Dart virtual machine Dart tools in Dartium or standalone dart2js JavaScript runs in all modern browsers Dart snapshot very fast startup

Dart Is Compatible With Modern Web Browsers http://buildbot.dartlang.org/

Translation To JavaScript There is a compiler that translates Dart to JavaScript (dart2js) The entire compiler is implemented in Dart Dart class Point { var x, y; Point(this.x, this.y); tostring() => "($x,$y)"; } JavaScript Point = { super: "Object", fields: ["x", "y"], tostring$0: function() { return '(' + str(this.x) + ',' + str(this.y) + ')'; } };

Dart Tree Shaking Tree shaking is a pre-deployment step that eliminates unused code Unused classes and methods are eliminated Applications are only penalized for what they use Easy process since Dart apps are declared Tree shaking is used by dart2js Reduces the download size Improves startup times

Dart Snapshots Binary form of an entire Dart app Speeds up loading by 10x Created by loading the app and serializing the heap Snapshots contain classes and methods Only works with the Dart VM Benefits No need to scan and parse source code Crucial on slower mobile devices

The Future Please put your sunglasses on

The Future of the Language The Dart language is frozen for the first version Except these few remaining issues: Eliminate interfaces and rely on abstract classes Introduce mixins for better sharing Add support for annotations

The Dart Timeline s! ces t an bus 2013 Suc t d fa st 2012 Ro t 2011 Dar asc Jav 2010 Spo 2009 ript...

Dart Developer Release in Fall 2012 We are serious about making Dart the next generation web app platform! The fall release will include: Language specification Libraries for web and server development Programming environment Virtual machine + browser integration Translator to JavaScript

Dart Is Open Source Dart is available under a BSD license Developed in the open (code reviews, build bots, etc.) Excited and active community Online resources Primary site - http://www.dartlang.org/ Code - http://dart.googlecode.com/ Libraries - http://api.dartlang.org/ Specification - http://www.dartlang.org/docs/spec/ Please try out Dart

More Dart @ Google I/O Wednesday 2:45-3:45pm: Putting the App Back into Web App (room 3) 4:00-5:00pm: Migrating Code from GWT to Dart (room 3) 2:45-6:45pm: Dart Office Hours (Chrome Demo Floor) Thursday 4:00-6:00pm: Bullseye - Your First Dart App (code lab)

Dart Summary Dart is an unsurprising object-oriented language, instantly familiar to most Dart allows you to write code that tools and programmers can reason about Dart applications work in all modern browsers by translating to JavaScript Making fast virtual machines is easy... try making a new language

Thank You! That is it folks... kasperl@google.com & bak@google.com