Today we are announcing
Dart 2 , a reload of the language that more fully reflects our vision of Dart as a uniquely optimized language for client development on the Web and mobile platforms.
Dash - the official language mascot
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.
Basic Dart Principles
Before we talk about innovations in Dart 2, it is worth understanding why we believe that Dart meets all the needs of the developers of client code.
')
In addition to the properties required for a modern general-purpose language, the 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 run performance should be excellent and predictable even on slower mobile devices.
- Ported . Client application developers need to think about 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 reactive programming style.
Dart is used to create mission-critical, high-quality applications on the Web, iOS, and Android in Google and other companies, and is great for mobile and web development:
- Dart increases the speed of development, because it has a clear, concise syntax and can work on 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 fast work on mobile devices, as well as transfiguration 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, allow 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 streams and futures ; also has good support for managing short-lived objects using the fast garbage collector.
Dart 2: Improved Customer Support
In Dart 2, we have taken a few things to make Dart an excellent language for writing client code. In particular, we 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, created one of Google’s largest and most advanced advertising management web applications; these services generate a significant portion of Google’s revenue. Working closely with these teams, we decided to strengthen the Dart type system. This will help Dart-programmers catch errors in the development process, better scale applications created by large teams, and improve the overall quality of the code.
Of course, this is nothing unique. The Web ecosystem also tends 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 reveals an implicit error and, as a result, helps to improve the overall quality of the code.
void main() { List<int> prices = ['99', '27', '10000', '20000000'];
What does this code do? You can expect it to print "27". But without the Dart 2 type system, he typed “10,000”, because this is the very first element in the list of lines, lexicographically ordered. However, with Dart 2, this code will generate 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 you use in an application often causes irritation. We aim 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 definition of a widget more clean and simple.
// 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 the most important uses for Dart is
Flutter , Google’s new mobile platform for creating user interfaces for iOS and Android.
The official app for the extremely popular
Hamilton: The Musical show - an example of how Flutter helps developers create 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 learning, reactive programming, high development speed and a high performance execution system with a fast garbage collector.
Web
Dart perfectly proved itself as a platform for critical web applications. It has web libraries such as
dart: html , as well as a full
web environment based on
dart . Teams using Dart for the Web were thrilled with the improved development speed. As Manish Gupta, vice president of development for Google AdWords, says:
The AdWords interface is large and complex, and it is crucial to Google’s revenue .
We chose Dart because of the excellent combination of productivity and predictability, ease of learning, type system and support in 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 quality applications for Android, iOS and the Web without any compromises, using a common code base. As a result, team members can smoothly move between platforms and help each other, for example, check the code. Teams like
AdWords Express and
AppTree reuse from 50% to 70% of their code on mobile devices and the Web.
Dart is
an open source project that supports the open standard
ECMA . We welcome contributions to both the
core Dart project and the growing
ecosystem of packages for Dart.
You can try Dart 2 in
Flutter and
Dart SDK directly from the command line. For Dart SDK, download Dart 2 from the dev channel and run your code with the flag
--preview-dart-2 . We also invite you to join our
gitter community.
Thanks to the improvements announced today, Dart 2 is a productive, clean and 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 Dart community in
Telegram or
Slack .