Friday, January 30, 2015

Dart Language Evolution Discussed in Ecma TC52

The Dart standards committee (ECMA TC52) met on January 14th, 2015. The committee discussed several areas where the language could be improved and agreed that these should be investigated in more detail, likely leading to detailed proposals over the next few months.

Configurable Imports

Some libraries only work on the server, or only on the client (in particular, if dart:html has been imported then a server execution is ruled out). There may be added support for some kind of conditional compilation such that different contexts may make different choices about which libraries to import.

Another proposal, which is much more complex and powerful, is concerned with parameterized libraries, e.g., libraries that may take type arguments or other libraries as arguments. Erik mentioned that the conditional compilation feature might already be included in the language, based on the ‘part’ mechanism, and Gilad agreed that that would be worth investigating, too.

Union Types

Union types have been proposed many times, and they have been postponed many times because the flexible nature of the Dart type system makes them less crucial than in some other languages. However, Javascript interoperability creates the greatest pressure for having them, because it is very common to use idioms in Javascript where a meaningful typing in Dart would rely on union types. Other cases could be functions taking an argument of a type T or of type Future<T>, leaving it up to the function to distinguish between the two cases.

First-class functions with different arity is another case. A problem with union types is that they tend to cause parsing conflicts; maybe they could be confined to typedef declarations, but that does not work well with generics; support for local typedefs may help. The operations allowed (when avoiding static type warnings) are just the ones in the common supertype of all operands of the union type operator, i.e., just the operations that are shared among all the types. Avoiding the accidentally shared operations (the ones that are declared independently in several operands) helps greatly avoiding a number of typing related complications.

It should be noted that union types may actually work quite well in Dart, especially because the assignability rules (rather than subtype rules) in the type system allows a value with a union type to be used where any of the operand types can be used.

Generic Methods

Dart does not currently support generic methods (aka polymorphic methods, i.e., methods taking type arguments), because of the strong expectation that they will be supported by type inference, which would add substantial complexity to the language and create conflicts with the basic design of Dart (e.g., the VM might be forced to perform inference at run time at heavy cost, or the reification of types would give user code access to compiler-selected type values, which could change over time due to seemingly remote and insignificant changes in the code). So the generic methods in Dart will not be supported by type inference, all type arguments must be given explicitly or they will be implicitly provided by the compiler as <dynamic..dynamic>. The syntax is not yet settled, and in particular there are ambiguity problems with several proposals (foo(a<b, c>(d)) may be seen as foo(_) or foo(_,_)).

Generalized Tear-Offs

The property extraction mechanism (aka closurization or tear-offs) creates some problems in the language: the current syntax does not work for operators, getters, setters, and constructors, and it is even creating problems for optimization because it is not known before runtime whether ‘a.m’ will need to be executed as a property extraction or as a getter invocation. New syntax is proposed for tear-offs, generally using ‘#’ rather than ‘.’ to separate the receiver and the selector. No particular difficulties are foreseen after an initial review. For backward compatibility, the old syntax and the new will coexist.

Null-Aware Operators

This feature has been requested for a long time! It is simply a small amount of syntactic sugar, but it may be quite convenient and it may be good for code readability. We propose a?.b (the Elvis operator), which just nulls out the result when a is null; a??b which evaluates to the value of b as a default when a evaluates to null; and a ?= b, which sets a to the value of b iff a is null.

Improvements to Type Promotion

This is purely a static type system issue, concerned with the typing of variables for which there is a type test in the preceding control flow. We currently have a few rules about type promotion, deliberately avoiding the highly elaborate versions that so many participants in this debate have requested. These rules are sound, but this is actually not particularly well motivated in a language like Dart. In many cases, users consider the results counterintuitive (“Why can’t it see that x is an int here, I just tested!?”). We may choose to use an unsound approach where the implied intentions of programmers are taken much more for granted, even though there can be exceptions at runtime.

Erik mentioned that if a pluggable type checker could remove certain type warnings then it could be delegated to a pluggable type checker (or several) to perform arbitrarily fancy flow analyses, and do extra type promotion. This means that type promotion in the spec can be very simple, and all the tricky special cases can be handled in a pluggable manner.

Minor Adjustments to the Existing Specification

We may change ‘await throw’ to throw immediately. The rules about type checking usages of objects whose class declares ‘noSuchMethod’ need generalization. The name 'main' should be allowed to be other things than a top-level-function (e.g., a const variable whose value is a suitable closure). Finally, allow doc comments to access imported scope.

Erik mentioned that there is a proposal to revise function type subtyping, and Gilad responded that there may be a need to adjust the specification in this respect, to be discussed at the next meeting.

Thursday, January 29, 2015

An interview with the author of Dart for Absolute Beginners

There are many books about the Dart language and libraries, but most assume some knowledge of programming. For people that are brand new to software development and want to learn Dart, there is now Dart for Absolute Beginners (Apress).We sat down with author David Kopec, to learn how people can begin their programming journey with Dart.



Q) On behalf of the Dart team, thanks for writing Dart for Absolute Beginners! So, how did you discover Dart?

David: Working in the startup world, I always try to keep abreast of exciting emerging technologies in the sphere of software development that may ease the lives of developers like myself. I first came across Dart in late 2012 while trying to get a consumer automotive web startup in LA off the ground. Dart was still in its early phases, but I was quickly enamored with its clean design and potential to ease Web development for both professionals and novices alike. I took a mental note and thought — this is something I need to come back to!

Q) What made you want to write a book about Dart?

David: I think when one is the solo author of a book about an emerging language/platform, more than anything else, you need to believe in its potential. I see Dart as an opportunity for a clean slate. It’s a fresh start incorporating all that we’ve learned about best practices for language design over the past 20 years. I see the industry spending a lot of time shoehorning older web technologies into places that they don’t necessarily fit well at scale. Dart is a better approach.

Clearly, I wanted to be a Dart advocate, because I truly believed that it’s a better way forward for the Web. The book was the natural offspring of my belief in Dart, desire to write a beginner’s book, and opportunity in my career time-wise to do it.

Q) Who should read the book? Who is the book for?

David: Dart for Absolute Beginners is truly designed for absolute beginners - individuals with no programming experience. It aims to be a broad introduction to programming, the Dart language, selected parts of the Dart platform, and the technologies behind the Web. In short, readers who want to learn Dart as a first programming language are the intended audience.

With that said, I have also received positive feedback from programmers with some experience that seek a Dart book with an eased learning curve.

Q) Why should people new to software development start with Dart?

David: Dart is a beautiful, clean, modern language, that comes with a batteries-included platform. Many people want to start their programming journey on the Web because of its immediacy and cross-platform compatibility. Yet, they end up having to tackle a hodgepodge of technologies, libraries, and frankly, a language, JavaScript, that has many inconsistencies.

Dart delivers all of the benefits of developing for the Web (immediacy, compatibility) but in an elegant, consistent package. New programmers don’t need to worry about language gotchas, because the language is clean and consistent. They don’t need to worry about what libraries they need for their project, because the Dart standard library is comprehensive. They don’t struggle with including additional functionality, because pub is so easy-to-use. They don’t need to worry about browser compatibility (too much) because the Dart team handles that for them as part of the unified platform. They don’t even need to think about which IDE/text editor to use because the platform comes with an easy-to-use one.

Another point worth mentioning, is that Dart includes modern object-oriented features that are nice transferable skills for when a new programmer wants to learn a second modern language like Java, Swift, or Ruby. Some of these advanced object-oriented features are sorely lacking in JavaScript. As a beginner, it’s nice to start in a place with your feet pointed towards the future.

Q) What makes Dart for Absolute Beginners special?

David: Dart for Absolute Beginners is the only book about Dart as a first programming language. All of the other books on the market assume at least a little bit of knowledge about another programming language. They are introductions to Dart, but not introductions to programming, Web technologies, and modern software development techniques for absolute beginners.

Beyond being an introduction to programming, Dart for Absolute Beginners also aims to be a broad introduction to modern Web software development techniques, in the sense that by the time the reader is done he or she will get a taste of version control with Git, unit testing, and even a basic understanding of HTTP. But my favorite feature is an included interview with the Dart project’s founders.

Q) How do you use Dart today?

David: I use Dart for client-side Web projects. I encourage consulting clients to have their projects built in Dart. I have not yet fully explored server-side Dart but it’s an area of future interest for me.

Q) What advice would you give to a developer learning Dart for the first time?

David: Beginning programmers often get frustrated by how far it is from Hello World to say making a graphical game. Don’t give up! Like anything else in life, programming takes time, practice, and dedication. Also, make sure you can walk before you attempt to run. I’ve seen beginners try to jump right into making a complicated Web app before they have mastered the basics of loops, data structures, and functions. That only leads to frustration. No matter what language you’re learning, the key is to have a solid foundation that you can build from. It’s not important to memorize all of the API calls in dart:html. You can always look those up. Memorization in programming isn’t especially helpful in the age of the search engine. Instead, beginners should work on building an understanding of language concepts.

Q) Where can developers follow you and your work?

David: My blog is Observational Hazard and I’m available for consulting projects through Oak Snow Consulting. You can also follow me on Twitter, G+, and GitHub.

Thanks David! Developers, new and experienced, can find Dart for Absolute Beginners at Amazon or Apress.

Monday, December 15, 2014

Enums and Async primitives in Dart

Support for enums, async, and deferred loading are now officially part of the 2nd revision of the Ecma-408 standard, the Dart Programming Language Specification. The second revision was approved last week at the Ecma General Assembly.


You can find more information about using the new features in our language tour on dartlang.org:

Enums

Enums help developers express clear intent with minimal code, and help tools catch potential bugs. Here is an example of an enumeration of form states:

    enum FormState { OPEN, INPROGRESS, CLOSED }

Tools can even warn developers if they omit an enum value from a switch statement, which helps identify potential bugs.



Async

Dart has always had strong support for asynchronous programming, with core library features such as Future and Stream. Now, with the new language primitives async and await, asynchronous code is much easier to read and write.

The following code is easy to read, because a developer can follow the logic, line by line. However, the lookUpVersion() function actually runs asynchronously!

checkVersion() async {
  var version = await lookUpVersion();
  if (version == expectedVersion) {
    // Do something.
  } else {
    // Do something else.
  }
}

Deferred loading

Users expect web applications to load extremely quickly. Dart's new deferred loading syntax helps a developer send minimal code to the client on the initial download, and load extra functionality on demand. This means that the user downloads only the code that they need to get started, resulting in faster load times.

Enjoy!

We are excited about these new language features and are working hard to provide full-fledged implementations of the new features in the Dart SDK as soon as possible. We look forward to your feedback on the new features.

Friday, November 28, 2014

Dart 1.8: library improvements and experimental support for enums

Would you like to try out Dart’s upcoming support for enums? In Dart Editor under Tools > Preferences > Experimental you can “Enable Enums Support” and start experimenting with code like:


With Dart 1.8, a number of library improvements have also landed. 
  • In dart:collection, SplayTree added toSet() method, and in dart:convert a JsonUtf8Encoder class was added. 
  • In dart:core, the following three things were added: 
    • New properties and constructors for RangeError
    • A new IndexError class - used by the RangeError.index constructor
    • Optional start and end arguments for the String.fromCharCodes constructor.
  • In dart:io we added support for the ALPN extension of the TLS secure networking protocol for Client and Server.
For a summary of these and others changes see the release notes. You can download Dart 1.8 from the Download Dart page. If you are running the Dart Editor, you can update by checking "About Dart Editor". Check out the Dart support page for information on getting help, filing issues, and contributing to the project.

Friday, November 7, 2014

Running Dart server applications on Google Cloud Platform

Today you can develop and deploy Dart server applications that run on the Google App Engine Managed VMs beta.

The productivity of the Dart language and libraries are a great fit for server applications. You get the competitive performance of the Dart VM while leveraging powerful tools like Observatory–all while easily sharing code with your browser application.

Now you can try Dart on Google App Engine, which lets you build and run applications on Google’s infrastructure. App Engine applications are easy to build, easy to maintain, and easy to scale as your traffic and data storage needs change. With App Engine, there are no servers for you to maintain. You simply upload your application and it’s ready to go.

Managed VMs extend App Engine to support user-defined custom runtimes. The Dart team is building on custom runtimes to allow you to easily develop and deploy Dart server applications that run on Google’s infrastructure.

Once you have set up your local development environment, you can quickly write and test your Dart server application using simulated App Engine Services–Datastore, Memcache, Logging, and more–on your development machine. A local admin interface gives you direct access to the services on the running instance. We’ve created several samples to get you started.

When you’re ready to deploy, App Engine gives you control over your application resources. You can also easily configure it to allow your application to automatically scale up and down in response to traffic. Once your site is live, you can monitor and manage your application using the browser-based Google Developers Console.

The Dart packages we are releasing today are beta, so we’d love your feedback. To participate in the discussion on running Dart on Managed VMs, and to stay informed with news and announcements, sign up for the Dart cloud Google Group. We are looking forward to your feedback so we can improve your experience with Dart and Google Cloud Platform.

To get started, visit dartlang.org/cloud.

Wednesday, October 22, 2014

WebStorm 9 released with improved Dart support

Today, JetBrains announced WebStorm 9, an update to their powerful web development editor. Highlights for the Dart developer include: pub serve support, improved isolates debugging, Observatory support, new syntax support, and more.

WebStorm 9 now launches pub serve, Dart's development server, when the developer runs a Dart web app. Pub serve takes care of generating assets, compiling to JavaScript, and more.

Developing and debugging apps that run multiple computations in parallel is now easier, thanks to the new ability to set breakpoints inside of isolates.



For deep insight into your app running on the Dart VM, you can now open the Observatory directly from WebStorm 9. Use the Observatory to learn how memory is used, where CPU time is spent, and more.



It's now easier to debug apps that use collections (which is every app), thanks to the debugger's logical view of maps and lists. Developers now see the logical data structure instead of internal implementation details.



WebStorm 9 now understands syntax for deferred loading and symbols. Deferred loading helps web apps start quickly, by delaying when libraries are loaded. Symbols are used when an identifier needs to remain unmodified after minification.

We encourage you to try WebStorm or IntelliJ IDEA for your Dart development, and we hope you enjoy these new features. We look forward to your feedback.

Wednesday, October 15, 2014

Dart 1.7: easily share and use command-line applications built with Dart


The Dart language, libraries, and runtime make it easy to create command-line applications. In fact, all of the core tools in the Dart SDK – dart2js, pub, and dartanalyzer – are written in Dart. We wanted to allow developers to easily get their own Dart scripts and command-line apps into users' hands. With Dart 1.7, users now have an easy way to install and run scripts built with Dart, making first-class command-line Dart apps a reality.

Developers can specify executables (Dart scripts) in their pub package, which are made available to a user when the package is installed.

Before:

$> git clone https://git.example.com/my_cool_app
$> cd my_cool_app
$> pub install
$> dart bin/my_cool_app.dart

Now:

$> pub global activate my_cool_app
$> my_cool_app

Dart 1.7 also includes improvements to our code isolation models. You can now launch isolates with a different package root than the host application, allowing for composition of Dart applications with different dependencies. For more robust servers and long-running Dart scripts, developers cans now easily handle errors thrown in child zones.

We've also made it easier to install and upgrade Dart SDK and Dartium. We now support Apt on Linux and Homebrew on Mac.

For a summary of these and others changes see the release notes. You can download Dart 1.7 from the Download Dart page. If you are running the Dart Editor, you can update by checking "About Dart Editor". Check out the Dart support page for information on getting help, filing issues, contributing to the project.