Dart 的编程语言之美 4 个超级特性

本文介绍了Dart编程语言的四个亮点特性:空安全、异步/await、函数参数定义的多种方式以及混合(mixins)的组合。Dart 2.12引入的空安全提供了编译时的空安全检查;异步/await简化了异步操作的处理;灵活的函数参数定义方式增强了代码的灵活性;混合(mixins)则允许在不使用继承的情况下实现组件化的功能添加。
摘要由CSDN通过智能技术生成

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-zEvsNDzX-1623715483769)(https://ducafecat.tech/2021/06/15/translation/the-beauty-of-the-flutters-programming-language-4-superb-features-of-dart/2021-06-15-07-58-44.png)]

老铁记得 转发 ,猫哥会呈现更多 Flutter 好文~~~~

微信 Flutter 技术群 ducafecat

原文

https://reprom.io/the-beauty-of-the-flutters-programming-language-4-superb-features-of-dart

参考

  • https://dart.dev/codelabs/async-await
  • https://medium.com/flutter-community/dart-what-are-mixins-3a72344011f3
  • https://dart.dev/guides/language/language-tour
  • https://api.dart.dev/stable/2.13.1/dart-isolate/dart-isolate-library.html

正文

在阅读 Flutter 时,我读到最多的缺点之一就是使用 Dart 编程语言。它还没有 Kotlin 那么成熟,这是我读到的最常被提及的论点之一。在我看来(我承认这可能会引起争议) ,Dart 是一种伟大的语言,我不会在 Flutter 创建应用程序时为其他任何语言改变它,我是在 Kotlin 专业地创建 android 应用程序之后说的,顺便说一句,这也是一种优雅而美丽的语言。

在这篇文章中,我打算展示我最喜欢的 Dart 编程语言的 4 个特性,没有特定的顺序; 让我们看看我们如何利用这个现代工具:

Null safety

最近在 2.12 版本中添加(包括在 Flutter 2.0 中)。在任何假装坚实和高效的现代语言中,空安全都是必须的。这就是为什么 Dart 团队一直致力于实现声音 null 安全,这意味着我们可以有可以为空的类型和不能为空的类型,如果我们尝试在后面执行一个不安全的操作,我们会在应用程序构建之前得到一个编译错误:

// This is a String that can be null
String? nullVar;

// This String cannot be null, the compiler forces me
// to set it a value because of its non-nullable nature.
String nonNullVar = 'I am not null';

// Alternatively, I can specify that the value will be
// set l
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
The Dart Programming Language By 作者: Gilad Bracha ISBN-10 书号: 0321927702 ISBN-13 书号: 9780321927705 Pages: 787 Dart is a class-based, object-oriented language that simplifies the development of structured modern apps, scales from small scripts to large applications, and can be compiled to JavaScript for use in any modern browser. In this rigorous but readable introductory text, Dart specification lead Gilad Bracha fully explains both the language and the ideas that have shaped it. The Dart Programming Language offers an authoritative description of Dart for programmers, computer science students, and other well-qualified professionals. The text illuminates key programming constructs with significant examples, focusing on principles of the language, such as optional typing and pure object-orientation. Bracha thoroughly explains reflection in Dart, showing how it is evolving into a form that programmers can easily apply without creating excessively large programs. He also shares valuable insights into Dart’s actor-style model for concurrency and asynchronous programming. Throughout, he covers both language semantics and the rationale for key features, helping you understand not just what Dart does, but why it works the way it does. You will learn about Dart’s object model, in which everything is an object, even numbers and Boolean values How Dart programs are organized into modular libraries How Dart functions are structured, stored in variables, passed as parameters, and returned as results Dart’s innovative approach to optional typing How Dart handles expressions and statements How to use Dart’s implementation of reflection to introspect on libraries, classes, functions, and objects Isolates and other Dart features that support concurrency and distribution
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值