-
Notifications
You must be signed in to change notification settings - Fork 0
DNET_Dart
一応、AltJS(JavaScriptの該当節を参照)(Flutter専用言語ではない)
- Googleによって開発されたウェブ向けのプログラミング言語
- 普及は進まず、2015年にはVMのChrome統合を断念
- TypeScript(JavaScriptの該当節を参照)をGoogle社内の標準プログラミング言語として承認
- しかし、2018年2月に発表されたDart2&Flutterが進撃を開始した。
- JavaScriptへのトランスパイラ以外にVMも持っている(FlutterはVMを使用)。
void main() {
print("Hello, World!");
}-
基本型
int、double、num、bool、Null、String -
配列
- List:一次元配列
- Set:ユニークな値の一次元配列
- Map:連想配列
-
その他
- Generic型
- dynamic型
-
型変換
.toString()など。 -
Null Safety(Flutterのセカンド・ステップの該当節を参照)
-
自動型推論
varを使用できる。 -
変数宣言キーワード
- const:定数
- final:変数だが初期化時以外の代入不可
-
命名規則
- 変数:lowerCamelCase
- クラス:UpperCamelCase
-
定義
<戻り値の型> <関数名>([<引数の型> <引数値>],[<引数の指定>]){ return <戻り値>; }-
public / private
-
private
関数名の先頭を「_」にする。 -
public
privateでなければ、publicになる。
-
-
instance / static
-
static
staticを付与する。 -
instance
staticでなければ、instanceになる。
-
-
戻り値
-
型の省略
helloWorld2(world){ return 'Hello $world'; }
-
非同期
Future<void> ...() async { ... }
-
-
-
引数
-
名前付き引数
"{}"内に定義する。computeSum({int val1, int val2}){ return val1 + val2; }
-
オプショナル引数
- オーバーロードは無いのでコレで対応できない場合はリネームする。
- "[]"内に定義して、nullを許容しないものには初期値を指定。
List<String> splitString(String input, [String split = ',', int max = 100]){ // 省略 }
-
-
ラムダ式
$はプレースホルダ-
ワンライナー(右辺に式)
String helloWorld4(String world) => 'Hello $world';
-
無名関数(右辺にコードブロック(クロージャ))
String helloWorld4(String world) { 'Hello $world'; };
-
-
new演算子
インスタンスの作成のnew演算子は省略可能 -
インターフェイス(抽象クラス)
クラス定義にabstractキーワードを使用する。 -
継承
- 具象クラス:extendsキーワードを利用して継承
- 抽象クラス:implementsキーワードを利用して継承
-
メンバ変数
- 先頭が「_」から始まるモノは、Internal相当。
- Flutterではthisは省略されることが多い。
-
メソッド
- オーバーライドはできる。
- オーバーロードはできない。
- ミックスインと言うメソッド追加の仕組みがある。
- mixinキーワードを利用してクラス風に定義して、
- withキーワードを利用して多重継承っぽく使用できる。
- 中から使う場合は、thisではなくsuperを使用するらしい。
-
コンストラクタ
- 略記の形式が幾つかある。
- 名前付きコンストラクタ
- リダイレクト・コンストラクタ
- Factoryコンストラクタ
- 抽象クラスで派生クラスを返したり
- シングルトンで返したりできる。
-
ゲッター・セッター
String _name; set name(String value){ _name = value; } String get name{ return _name; }
-
libraryで名前をつけられる。
-
libraryを明示しなくても自動的に
タグがつけられてライブラリとして扱われる。 -
dart:で始まるライブラリと、
package:で始まるその他のライブラリがある。
partとpart ofでlibraryのファイル分割が可能。
-
import
-
ライブラリを読み込む
-
同じパッケージ内のライブラリ(≒ファイル)
-
パッケージ名のlib以下の仮想パスで指定。
import 'package:my_package/src/other_library.dart';
-
自ファイルからの相対パスで指定。
import 'src/other_library.dart'; import '../other_library.dart';
-
-
-
export
-
外部に公開するライブラリを指定する。
-
メインのライブラリにexportを記述すると、
メインのライブラリを読み込むだけで、
exportされたライブラリにアクセスできる。
-
オプション
-
show
- import / exportで利用可能。
- 指定したクラスや関数のみを参照
-
hide
- import / exportで利用可能。
- 指定したクラスや関数を参照しない
-
as
- importでのみ利用可能。
- 指定したクラスに別名を指定
- C#のusing エイリアス(別名) ディレクティブ的な。
-
deferred
- importでのみ利用可能。
- deferred asで、エイリアス利用時まで遅延ロード
Promise (JavaScript)とほぼ同様
-
LINQのようなもの。
-
RxDart
≒Reactive Extensions(Rx)系
- 配列またはオブジェクトの要素を展開する。
- ECMAScriptにもあるヤツ(ECMAScriptの該当節を参照)。
-
Dart - Wikipedia
https://ja.wikipedia.org/wiki/Dart -
Dart programming language | Dart
https://dart.dev/#try-dart
-
グーグルから「JavaScriptは根本的な問題を抱えている」とのメモがリークか
https://www.publickey1.jp/blog/11/javascript_6.html -
グーグル、新言語「Dart」を発表。
JavaScriptのようなWebプログラミングを想定
https://www.publickey1.jp/blog/11/dartjavascriptweb.html -
Googleの新言語「Dart」、ECMAが標準化を開始
https://www.publickey1.jp/blog/13/googledartecma.html -
ChromeへのDartVM統合を断念、Dart開発チームが発表。
今後はJavaScriptへのコンパイルにフォーカス
https://www.publickey1.jp/blog/15/chromedartvmdart.html -
Google社内の標準言語としてTypeScriptが承認される。ng-conf 2017
https://www.publickey1.jp/blog/17/googletypescriptng-conf_2017.html -
TypeScriptが標準言語になっても、
Dartのことは忘れてませんよとGoogle担当者がフォロー
https://www.publickey1.jp/blog/17/typescriptdartgoogle.html -
Googleが「Dart 2」発表、Dartを再起動。
iOS/Android用ライブラリ「Flutter」と共に
Webとモバイルのクライアント開発にフォーカス
https://www.publickey1.jp/blog/18/googledart_2dartiosandroidfultterweb.html -
人気が下降しプログラマの求人も少ないプログラミング言語ワースト10は?
一方で仕事の多い言語は? CodementorXとCoding Dojoの調査結果
https://www.publickey1.jp/blog/18/5_codementorxcoding_dojo.html
-
Flutterで始めるモバイルアプリ開発連載一覧
https://codezine.jp/article/corner/830- Flutter開発で必要なDart言語の基本を理解しよう
https://codezine.jp/article/detail/13498 - Flutter開発で使うDart言語での関数・クラスの使い方を理解しよう
https://codezine.jp/article/detail/13586 - Dart言語でのプログラム設計でワンランク上を目指そう
https://codezine.jp/article/detail/13665
- Flutter開発で必要なDart言語の基本を理解しよう
すぐにFlutterを始めたい人のためのDart入門
- 前編
https://itome.team/blog/2019/12/flutter-advent-calendar-day3 - 後編
https://itome.team/blog/2019/12/flutter-advent-calendar-day4
-
Dart逆引きリファレンス
https://dev.classmethod.jp/articles/dart_reference_index/- 導入(Getting started)
https://dev.classmethod.jp/etc/dart_reference_getting_started/ - コードのモジュール化(Code modularity)
https://dev.classmethod.jp/client-side/dart_reference_code_modularity/ - 変数(Variables)
https://dev.classmethod.jp/client-side/dart_reference_variables/ - コレクション(Collections)
https://dev.classmethod.jp/client-side/dart_reference_collection/ - 文字列(Strings)
https://dev.classmethod.jp/client-side/dart_reference_strings/ - 真偽値(Booleans)
https://dev.classmethod.jp/client-side/dart_reference_booleans/ - 関数(Functions)
https://dev.classmethod.jp/client-side/dart_reference_functions/ - 反復処理(Iterators)
https://dev.classmethod.jp/client-side/dart_reference_iterators/ - クラス(Classes)
https://dev.classmethod.jp/client-side/dart_reference_classes/ - DOM要素の問い合せ(Finding elements in DOM)
https://dev.classmethod.jp/client-side/dart_reference_finding_elements_in_dom/ - DOMの操作(Manipulating DOM)
https://dev.classmethod.jp/client-side/dart_reference_manipulating_dom/ - 正規表現(Regular expressions)
https://dev.classmethod.jp/client-side/dart_reference_regular_expressions/ - 例外(Exceptions)
https://dev.classmethod.jp/client-side/dart_reference_exceptions/ - イベントハンドリング(Event handling)
https://dev.classmethod.jp/client-side/dart_reference_event_handling/ - タイミング(Timing)
https://dev.classmethod.jp/client-side/dart_reference_timing/ - HTML属性(HTML attributes)
https://dev.classmethod.jp/client-side/dart_reference_html_attributes/ - CSSクラス(CSS Classes)
https://dev.classmethod.jp/client-side/dart_reference_css_classes/ - Ajax
https://dev.classmethod.jp/client-side/dart_reference_ajax/ - jQuery
https://dev.classmethod.jp/client-side/dart_reference_jquery/ - 数値処理(Math)
https://dev.classmethod.jp/client-side/dart_reference_math/ - 実行時プログラム操作(Run time program manipulation)
- 導入(Getting started)
移行メモ
- ラムダ式の説明にあった全角の「$」は、直後のコード例に合わせて 半角の
$とした。また「ワンライナー(右辺に式」「無名関数(右辺にコードブロック(クロージャ」の 閉じ括弧の欠落を補った。- 「ワンライナー」「無名関数」の 2 つの例は元 Wiki の時点で 同じ関数名(helloWorld4)になっている。
- マイクロソフト系技術情報 Wiki(techinfoofmicrosofttech.osscons.jp)への URL リンクは、移行済みの LINQ / Reactive Extensions(Rx) に張り替えた。
- PukiWiki のページ内アンカ(
#xxxxxxxx)は GitHub Wiki では再現できないため、 同一ページ内のアンカは見出しから生成されるアンカに張り替え、 他ページのアンカを指すリンクは「〜(ページ名の該当節を参照)」の形に置き換えた。- 本フェーズで新たに参照された「async/await (JavaScript)」を TODO.md に予約した。
Tags: 移行, Dart, Flutter, AltJS, 型, クラス, library, 非同期処理, Stream
このWikiは「Open棟梁Project」,「OSSコンソーシアム 開発基盤部会」によって運営されています。