Dart (https://www.dartlang.org/) is a general-purpose programming language to build web, server, IoT and mobile applications.
AngularDart (https://webdev.dartlang.org/angular) - also called Angular 2 for Dart or simply Angular - is a web app framework that focuses on productivity, performance, and stability. Hundreds of Google engineers use AngularDart to build the sophisticated, mission-critical apps that bring in much of Google’s revenue.
Flutter (https://www.flutter.io/) is a promising project to build mobile apps for iOS and Android from a single codebase in Dart.
Dart, AngularDart and Flutter significantly increase the productivity of the developers.
Slides from following meetup
https://www.meetup.com/Luxembourg-Dart-Lang-Meetup/events/237012072/
4. DISCOVER DART(LANG) - INTRODUCTION
DART LANGUAGE: ORIGINS
▸ Open Source Software under a BSD license
▸ Starting in October 2011
▸ Originally developed by Google
▸ Approved as a standard by Ecma in June 2014: ECMA-408
▸ Designed by Lars Bak and Kasper Lund
▸ Legacy developers of V8 Javascript Engine used in Chrome
6. DISCOVER DART(LANG) - INTRODUCTION
DART LANGUAGE: PURPOSES
▸ General-purpose and multi-platform programming language
▸ Easy to learn
▸ Easy to scale
▸ Deployable everywhere
▸ Web (Angular Dart), Mobile (Flutter), Server (VM)
▸ Command Line, IoT…
7. DISCOVER DART(LANG) - INTRODUCTION
DART LANGUAGE: ON PRODUCTION
▸ Google depends on Dart to make very large applications
▸ AdWords, AdSense, Internal CRM, Google Fiber…
▸ Over 2 million lines of production Dart code
Apps can reach hundreds of thousands of lines of code
▸ ReyeR has developed with Dart for 4 years now
▸ BikeMike.Mobi, Daanuu
8. DISCOVER DART(LANG) - INTRODUCTION
DART’S NOT JUST A LANGUAGE
▸ Well-crafted core libraries
▸ pub: a Package Manager
▸ Packages are available at pub.dartlang.org
▸ dartanalyzer: a static Analysis Tool for real-time analysis and code completion
▸ dartfmt: a source code reformatter for common coding conventions
▸ dartdoc: generate HTML documentation (triple slashes comments (///))
▸ dartium: a Web browser with Dart included (based on Chromium)
▸ …Unit test, Code Coverage, Profiling….
10. DISCOVER DART(LANG) - LANGUAGE
HELLO WORLD
void main() {
for (int i = 0; i < 5; i++) {
print('hello ${i + 1}');
}
}
$ dart hello_world.dart
hello 1
hello 2
hello 3
hello 4
hello 5
11. DISCOVER DART(LANG) - LANGUAGE
KEYWORDS
▸ class abstract final static implements extends with
▸ new factory get set this super operator
▸ null false true void const var dynamic typedef enum
▸ if else switch case do for in while assert
▸ return break continue
▸ try catch finally throw rethrow
▸ library part import export deferred default external
▸ async async* await yield sync* yield*
13. DISCOVER DART(LANG) - LANGUAGE
IMPORTANT CONCEPTS
▸ Everything is an object
▸ Even numbers, booleans, functions and null are objects
▸ Every object is an instance of a class that inherit from Object
▸ Everything is nullable
▸ null is the default value of every uninitialised object
▸ Static types are recommended for static checking by tools, but it’s optional
▸ If an identifier starts with an underscore (_), it’s private to its library
14. DISCOVER DART(LANG) - LANGUAGE
VARIABLES
var name = 'Bob';
var number = 42;
int number;
String string;
int number = 42;
String name = 'Bob';
15. DISCOVER DART(LANG) - LANGUAGE
FUNCTION: FAT ARROW
bool isNoble(int number) {
return _nobleGases[number] != null;
}
bool isNoble(int number) => _nobleGases[number] != null
=> expr syntax is a shorthand for { return expr; }
17. DISCOVER DART(LANG) - LANGUAGE
FUNCTION: OPTIONAL POSITIONAL PARAMETERS
String say(String from, String msg, [String device]) {
var result = '$from says $msg';
if (device != null) {
result = '$result with a $device';
}
return result;
}
assert(say('Bob', 'Howdy') == 'Bob says Howdy’);
assert(say('Bob', 'Howdy', 'phone') == 'Bob says Howdy with a phone');
18. DISCOVER DART(LANG) - LANGUAGE
CLASS / CONSTRUCTOR / NAMED CONSTRUCTORS
import 'dart:math';
class Point {
num x;
num y;
Point(this.x, this.y);
Point.fromJson(Map json) {
x = json['x'];
y = json['y'];
}
...
...
num distanceTo(Point other) {
var dx = x - other.x;
var dy = y - other.y;
return sqrt(dx * dx + dy * dy);
}
}
19. DISCOVER DART(LANG) - LANGUAGE
CASCADE NOTATION
var address = getAddress();
address.setStreet(“Elm”, “42”)
address.city = “Carthage”
address.state = “Eurasia”
address.zip(1234, extended: 5678);
getAddress()
..setStreet(“Elm”, “42”)
..city = “Carthage”
..state = “Eurasia”
..zip(1234, extended: 5678);
result = x ?? value;
// equivalent to
result = x == null ? value : x;
x ??= value;
// equivalent to
x = x == null ? value : x;
p?.y = 4;
// equivalent to
if (p != null) {
p.y = 4;
}
NULL AWARE OPERATORS
20. DISCOVER DART(LANG) - LANGUAGE
FUTURE & ASYNCHRONOUS
Future<String> lookUpVersion() async => '1.0.0';
Future<bool> checkVersion() async {
var version = await lookUpVersion();
return version == expected;
}
try {
server = await HttpServer.bind(InternetAddress.LOOPBACK_IP_V4, 4044);
} catch (e) {
// React to inability to bind to the port...
}
22. DISCOVER DART(LANG) - GETTING STARTED
TRY DART ONLINE
▸ Online with DartPad https://dartpad.dartlang.org/
Supports only a few core libraries
23. DISCOVER DART(LANG) - GETTING STARTED
INSTALL DART ON YOUR FAVORITE PLATFORM
▸ Install Dart on MacOS, Linux Ubuntu/Debian, Windows
▸ Install an IDE
▸ Recommended: WebStorm or IntelliJ (for Flutter)
▸ Dart Plugins available for
▸ Atom, Sublime Text 3, Visual Studio Code, Emacs, Vim