Today Google released version 2.15 of the Dart SDK, featuring fast concurrency with worker isolates, a new constructor tear-off language feature, improved enum support in the dart:core library, new features for package publishers, and more.
Dart is a programming language developed by Google for developing fast apps on any platform. Its goal is to offer the most productive programming language for multi-platform development, paired with a flexible execution runtime platform for app frameworks.
Dart is particularly suited to client development, prioritizing both development and high-quality production experiences across a wide variety of compilation targets (web, mobile, and desktop).
Dart also forms the foundation of Flutter. Dart provides the language and runtimes that power Flutter apps, but Dart also supports many core developer tasks like formatting, analyzing, and testing code.
The Dart language is type safe; it uses static type checking to ensure that a variable’s value always matches the variable’s static type. Sometimes, this is referred to as sound typing. Although types are mandatory, type annotations are optional because of type inference. The Dart typing system is also flexible, allowing the use of a dynamic type combined with runtime checks, which can be useful during experimentation or for code that needs to be especially dynamic.
Dart offers sound null safety, meaning that values can’t be null unless you say they can be. With sound null safety, Dart can protect you from null exceptions at runtime through static code analysis. Unlike many other null-safe languages, when Dart determines that a variable is non-nullable, that variable is always non-nullable. If you inspect your running code in the debugger, you’ll see that non-nullability is retained at runtime (hence sound null safety).
Fast concurrency with worker isolates
Just about all modern devices have CPUs with multiple cores, capable of running multiple tasks in parallel. For most Dart programs, how these cores are used is transparent to you as a developer: the Dart runtime system by default runs all your Dart code on a single core, but then uses additional cores for executing systems-level tasks such as async input/output, like writing a file or making a network call.
But your Dart code itself may need to run concurrently. For example, you may have a continuous animation and a long-running task such as parsing a large JSON file. If the additional task takes too long, that might cause stutter or lag in the UI. By moving those additional tasks to a separate core, the animation can continue to run on the main thread of execution, uninterrupted.
Dart’s model for concurrency is based on isolates — independent units of execution that are isolated from one another — to prevent a large class of concurrency programming bugs related to shared memory, such as race conditions like data races. Dart prevents these bugs by not allowing any mutable objects to be shared between isolates, and instead uses a model where isolates exchange state using message passing. In Dart 2.15 we’ve made a number of substantial enhancements to isolates.
New language feature: Constructor tear-offs
In Dart you can create a function object, which points to a function on another object, by using the function’s name. Such function pointers — also referred to as function tear-offs — appear frequently when using the Dart core libraries.
Improved enums in the dart:core library
We’ve made a number of convenience additions to the enum APIs in the dart:core library (language issue #1511). You can now get the String value for each enum value using .name
Compressed pointers
Dart 2.15 adds support for compressed pointers, a technique where a 64-bit SDK can use a more space-efficient representation of pointers if only a 32-bit address space needs to be supported (up to 4 GB of memory). Compressed pointers result in a significant memory reduction; in our internal testing with the GPay app, we saw an approximately 10% reduction of the Dart heap size.
Because compressed pointers imply not being able to address any available RAM above 4 GB, the feature is behind a configuration option in the Dart SDK that can only be toggled by embedders of the Dart SDK when the SDK is built. The Flutter SDK version 2.8 has enabled this configuration for Android builds, and the Flutter team is considering also enabling it for iOS builds in a future release.
Dart DevTools included in the Dart SDK
The DevTools suite of debugging and performance tools previously wasn’t in the Dart SDK; you had to download it separately. Starting with Dart 2.15, you now get DevTools when you download the Dart SDK, with no further installation steps required. For more information on using DevTools with Dart command-line apps, see the DevTools documentation.
New pub features for package publishers
Dart 2.15 SDK also has two new features in the dart pub developer command and the pub.dev package repository.
First, there’s a new security feature for package publishers. The aim is to detect when a publisher accidentally publishes secrets — for example Cloud or CI credentials — inside pub packages. We were inspired to add this leak detection after learning that inside GitHub repositories, thousands of secrets are leaked every day.
Leak detection runs as part of the pre-publish validation run in the dart pub publish command. If it detects a potential secret in the files about to be published, the publish command exits without publishing, and prints a warning message.
Dart is a modern, object-oriented programming language developed by Google, initially released in 2011. Dart was designed with the goal of making it easy to build high-performance web applications. It has many features that make it a good choice for building web and mobile applications.
Some key features of Dart include:
Strong typing: Dart is a statically-typed language, which means that the type of a variable is checked at compile time. This helps catch errors early in the development process.
Garbage collection: Dart has a garbage collector that automatically manages memory for you, freeing up memory that is no longer being used.
Asynchronous programming: Dart has built-in support for asynchronous programming, making it easy to write non-blocking code that can handle I/O operations without blocking the main thread.
Flutter: Dart is also the primary programming language used for developing mobile applications using the Flutter framework. Flutter is a popular framework for building mobile apps that allows developers to create beautiful, high-performance apps for both iOS and Android.
Dart has a simple syntax that is easy to learn for developers with experience in other languages like JavaScript, Java, or Python. It has a growing community and a number of libraries and tools that make it easier to build applications. Additionally, Dart is an open-source project, so anyone can contribute to its development.
Dart is a general-purpose, object-oriented programming language developed by Google. It was designed to be easy to learn, easy to use, and suitable for a wide range of applications, from small scripts to large, complex systems.
Dart was first introduced in 2011, and it has since undergone several updates and revisions. It features a modern syntax, including support for asynchronous programming, and has a strong focus on performance.
One of the main advantages of Dart is its ability to be used both on the client-side, in web development, and on the server-side, in building back-end systems. In addition, it also has the ability to be compiled to native code, which allows it to be used in mobile and desktop applications.
Dart has its own runtime, the Dart VM, which can execute Dart code directly. It can also be compiled to JavaScript, allowing Dart code to be run in web browsers. Additionally, Dart supports interoperability with other languages, including JavaScript and C++.
Overall, Dart is a versatile and powerful programming language that offers a range of features and benefits for both novice and experienced developers.