Google has released version 2.15 of the Dart programming language, continuing the development of the significantly revamped Dart 2 branch, which differs from the original Dart language by employing strong static typing (types can be inferred automatically, so specifying types is not mandatory, but dynamic typing is no longer used, and the initially inferred type is fixed to the variable, applying strict type checking thereafter).
Features of the Dart language:
- Familiar and easy-to-learn syntax, natural for programmers coming from JavaScript, C, and Java.
- Ensuring quick startup and high performance for all modern web browsers and various environments, from mobile devices to powerful servers. servers.
- Ability to define classes and interfaces, allowing for encapsulation and reuse of existing methods and data.
- Type specification simplifies debugging and error detection, makes the code clearer and more readable, and eases further development and analysis by external developers.
- Supported types include various types of hashes, arrays and lists, queues, numeric and string types, types for defining date and time, and regular expressions (RegExp). There is an option to create custom types.
- For organizing concurrent execution, it is suggested to use classes with the isolate attribute, whose code runs entirely in an isolated space in separate memory, interacting with the main process via message passing.
- Support for libraries that simplify maintenance and debugging of large web projects. Third-party function implementations can be included as shared libraries. Applications can be divided into parts, allowing each part to be developed by separate teams of programmers.
- A set of ready-made tools to support development in Dart, including implementations for dynamic development and debugging with on-the-fly code fixes (‘edit-and-continue’).
- To simplify development in the Dart language, an SDK, a package manager pub, a static code analyzer dart_analyzer, a set of libraries, the integrated development environment DartPad, and Dart support plugins for IntelliJ IDEA, WebStorm, Emacs, Sublime Text 2, and Vim are provided.
- Additional packages with libraries and utilities are distributed through the pub repository, which contains about 22 thousand packages.
Key changes in the Dart 2.15 release:
- Tools for rapid parallel execution of tasks with isolated handlers have been provided. On multi-core systems, the Dart runtime by default executes application code on one CPU core while utilizing other cores to handle system tasks such as asynchronous I/O, file writing, or making network calls. For applications that need to run their handlers in parallel, for instance, for rendering animations in the interface, there is an option to run separate blocks of code (isolate), which are isolated from each other and executed on different CPU cores simultaneously with the main application thread. To protect against errors that can arise from simultaneous execution of code that operates on the same set of data, sharing mutable objects is prohibited in different isolate blocks, and a message-passing model is used for interaction between handlers.
In Dart 2.15, a new concept called isolate groups has been introduced, allowing for organized shared access to various internal data structures in isolate blocks that belong to the same group, significantly reducing overhead when handlers interact within the group. For example, launching an additional isolate block in an existing group is performed 100 times faster and requires 10-100 times less memory than launching a standalone isolate block, thanks to eliminating the need to initialize program data structures.
Although shared access to mutable objects is still prohibited in isolate blocks within groups, shared heap memory is used in groups, significantly speeding up the transfer of objects from one block to another without the need for resource-intensive copying operations. In the new version, it is also allowed to pass the result of the handler when calling Isolate.exit() to transfer data to the parent isolate block without copying operations. Additionally, the message-passing mechanism has been optimized — small and medium messages are now processed approximately 8 times faster. The types of objects that can be passed between isolate blocks using the SendPort.send() call now include certain types of functions, closures, and stack traces.
- The tools for creating pointers to individual functions in other objects (tear-off) have removed the restrictions on creating such pointers in constructor code, which can be useful when building interfaces based on the Flutter library. For example, to create a Column widget that includes several Text widgets, you can call “.map()” and pass pointers to the Text constructor of the Text object: class FruitWidget extends StatelessWidget { @override Widget build(BuildContext context) { return Column( children: [‘Apple’, ‘Orange’].map(Text.new).toList()); } }
- The capabilities related to using function pointers have been expanded. It is now possible to apply generic methods and function pointers to create a non-generic method and pointer: T id(T value) => value; var intId = id; // allowed in version 2.15 instead of ‘int Function(int) intId = id;’ const fo = id; // pointer to the function id. const c1 = fo;
- The dart:core library has improved support for enumerations (enum); for example, you can now output the string value of each enum value using the ‘.name’ method, select values by name, or perform value pair matching: enum MyEnum { one, two, three } void main() { print(MyEnum.one.name); // will output ‘one’. print(MyEnum.values.byName(‘two’) == MyEnum.two); // will output ‘true’. final map = MyEnum.values.asNameMap(); print(map[‘three’] == MyEnum.three); // ‘true’. }
- Pointer compression technology has been implemented, allowing for a more compact representation of pointers in 64-bit environments when addressing requires only a 32-bit address space (utilizing no more than 4 GB of memory). Tests have shown that this optimization can reduce heap size by approximately 10%. In the Flutter SDK, this new mode is enabled by default for Android, and plans to activate it for iOS are scheduled for a future release.
- The Dart SDK includes debugging and performance analysis tools (DevTools) that were previously supplied in a separate package.
- Tools for monitoring accidental publication of sensitive information have been added to the 'dart pub' command and the pub.dev package repositories, such as leaving CI system credentials inside a package. If such leaks are detected, the execution of the 'dart pub publish' command will be aborted with an error message. If a false positive occurs, there is an option to bypass the check via a whitelist.
- The pub.dev repository has introduced the ability to revoke already published package versions, for example, in cases of dangerous bugs or vulnerabilities. Previously, the practice was to publish a subsequent patch version to fix such issues, but in some situations, it is necessary to revoke the release completely and stop its further distribution urgently (for instance, if the fix is not yet ready or if a production release was mistakenly published instead of a test version). Once revoked, the package will no longer be recognized in the 'pub get' and 'pub upgrade' commands, and on systems that have already installed it, a special warning will be displayed upon the next execution of 'pub get'.
- Protection against the vulnerability (CVE-2021-22567), caused by the use of unicode characters in the code that change the display order, has been added.
- The vulnerability (CVE-2021-22568), which allows impersonation of another user on pub.dev when publishing packages to a third-party server that accepts pub.dev oauth2 access tokens, has been addressed. For example, this vulnerability could be used to attack internal and corporate package servers. Developers who only host packages on pub.dev are not affected by this issue.
A significant release of the Flutter 2.8 user interface framework has been introduced, seen as an alternative to React Native and enabling the development of applications for iOS, Android, Windows, macOS, and Linux from a single codebase, as well as applications for running in browsers. A custom shell developed for Google's microkernel operating system Fuchsia is based on Flutter. It is noted that in the last six months, the number of apps on Flutter 2 in the Google Play Store has increased from 200,000 to 375,000, nearly doubling.
The core of Flutter's code is implemented in Dart, while the runtime engine for executing applications is written in C++. In addition to Dart, the native language for Flutter, developers can utilize the Dart Foreign Function interface to call code written in C/C++. High performance is achieved through compiling applications to machine code for the target platforms. Importantly, programs do not need to be recompiled after each change as Dart provides a hot reload mode, allowing changes to be made in a running application and evaluated immediately.
The new Flutter release includes optimizations for launch speed and memory consumption on mobile devices. Connecting applications to backend services such as Firebase and Google Cloud has been simplified. Tools for integration with Google Ads have been stabilized. Camera support and web plugins have seen significant improvements. New tools for simplifying development have been introduced, including a widget for Firebase authentication. The Flame engine, intended for developing 2D games with Flutter, has been updated.
Source: opennet.ru
