Dart 2.0 Announcement: Optimized for Client Development

Original author: Anders Thorhauge Sandholm
  • Transfer
Today we are announcing Dart 2 , a language reload that more fully reflects our vision of Dart as a uniquely optimized language for client development on the Web and mobile platforms.

Dash - official language mascot
Dash - the official mascot of the language

With Dart 2, we significantly strengthened and simplified the type system, cleared the syntax and rewrote most of the tools from scratch to make mobile and web development more enjoyable and productive. Dart 2 also takes into account lessons learned from early language users, including Flutter , AdWords, and AdSense , as well as thousands of improvements, large and small, made in response to customer feedback.

Dart Fundamentals


Before talking about the innovations in Dart 2, it’s worthwhile to understand why we believe that Dart meets all the needs of client code developers.

In addition to the properties necessary for a modern general-purpose language, a language for client development should be:

  • Productive . The syntax should be clear and concise, the toolkit should be simple, and the development cycle should be almost instantaneous.
  • Quick . Launch and runtime performance should be excellent and predictable even on slow mobile devices.
  • Portable . Client application developers should think of three platforms today: iOS, Android, and Web. Language should work well on all of them.
  • Affordable . A language cannot go too far from familiar things if it wants to remain understandable to millions of developers.
  • Reactive . The language must support a reactive programming style.

Dart is used to create mission-critical, high-quality applications on the Web, iOS and Android at Google and other companies and is great for mobile and web development:

  • Dart increases development speed because it has a clear, concise syntax and can work in a virtual machine with a JIT compiler. This allows you to support a hot reboot during the mobile development process, which leads to super fast development cycles where you can edit, compile and replace code in an already running application on the device.
  • Due to its ability to efficiently compile source code in advance , Dart provides predictable and high performance as well as quick launch on mobile devices.
  • Dart supports compilation into native code (ARM, x86, etc.) for quick work on mobile devices, as well as translation into effective JavaScript code for the Web.
  • Dart is understandable to most developers thanks to its object-oriented aspects and syntax, which, according to our users, allows C ++, C #, Objective-C or Java developers to write Dart code in just a few days.
  • Dart with its SDK is well suited for reactive programming; it includes threads and futures ; also has good support for managing short-lived objects with a quick garbage collector.

Dart 2: Improving Customer Support


In Dart 2, we did a few things to make Dart a great language for writing client-side code. In particular, we have added several new features, including strong typing and improving how the user interface is defined through code.

Strong typing


The teams behind AdWords and AdSense, using Dart, have created one of Google’s largest and most advanced web-based advertising management applications, and these services generate a significant share of Google’s revenue. Working closely with these teams, we decided to strengthen the Dart type system. This will help Dart programmers catch errors during the development process, better scale applications created by large teams, and improve the overall quality of the code.

Of course, this is nothing unique. There is also a tendency in the Web ecosystem to add types to JavaScript. For example, TypeScript and Flow extend JavaScript with annotations and type inference to improve code analysis capabilities.

In the small example below, Dart 2 detects an implicit error and, as a result, helps improve the overall quality of the code.

void main() {
  List prices = ['99', '27', '10000', '20000000'];
  // Отсортировать цены от низких к высоким
  prices.sort();
  print('Самая низкая цена: ${prices[0]}!');
}

What does this code do? You can expect him to print “27”. But without the Dart 2 type system, he printed “10000” because it is the very first element in the list of strings ordered lexicographically. However, with Dart 2, this code will produce a typing error.

User Interface Through Code


When creating a user interface, the need to switch between a separate markup language and the programming language that you use in the application is often annoying. We strive to reduce the need for context switching. Dart 2 introduces the optional new and const . This functionality is very valuable in itself, and also opens up other possibilities . For example, thanks to the optional new and const, we can make the widget definition cleaner and simpler.

// До Dart 2
Widget build(BuildContext context) {
  return new Container(
    height: 56.0,
    padding: const EdgeInsets.symmetric(horizontal: 8.0),
    decoration: new BoxDecoration(color: Colors.blue[500]),
    child: new Row(
      ...
    ),
  );
}
// После Dart 2
Widget build(BuildContext context) =>
  Container(
    height: 56.0,
    padding: EdgeInsets.symmetric(horizontal: 8.0),
    decoration: BoxDecoration(color: Colors.blue[500]),
    child: Row(
      ...
    ),
  );

Using Dart on the Client Side


Mobile platforms


One of Dart’s most important uses is Flutter , Google’s new mobile platform for creating user interfaces for iOS and Android. The official app for the hugely popular Hamilton: The Musical show is an example of how Flutter helps developers build apps in record time. Flutter uses a reactive programming style and controls the user interface pixel by pixel. For Flutter, Dart is ideally suited in terms of ease of training, reactive programming, high development speed and high performance runtime system with fast garbage collector.

Web


Dart has proven itself as a platform for mission-critical web applications. It has web libraries such as dart: html , as well as a complete Dart-based web environment . Teams using Dart for the Web were enthusiastic about improving development speed. According to Manish Gupta, vice president of development for Google AdWords:
The AdWords interface is large and complex, and it is critical to Google’s revenue .
We chose Dart because of the excellent combination of productivity and predictability, ease of training, type system and support on the Web and mobile devices .
Our engineers are two to three times more productive than before, and we are glad that we switched to Dart.

What's next


With Flutter and Dart, developers finally got the opportunity to write high-quality applications for Android, iOS and Web without any compromises, using a common code base. As a result, team members can seamlessly move between platforms and help each other, for example, checking the code. Commands such as AdWords Express and AppTree reuse between 50% and 70% of their code on mobile devices and the Web.

Dart is an open source project that supports the open ECMA standard . We welcome contributions to both the core Dart project and the growing ecosystem of Dart packages .

You can try Dart 2 in Flutter andDart SDK directly from the command line. For the Dart SDK, download Dart 2 from the dev channel and run your code with the --preview-dart-2 flag . We also invite you to join our gitter community .

Thanks to the improvements announced today, Dart 2 is a productive, clean and field-proven language that solves the problems of developing modern applications. He is already loved by some of the most demanding developers on the planet, and we hope that you will like it too.

Translator's Note : Join the Russian-speaking Dart community in Telegram or Slack .

Also popular now: