Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Bullseye: An introduction to Dart

Sebastian
October 29, 2016

Bullseye: An introduction to Dart

Let's dive into the language straight. You do not need any knowledge of the language prior to this. I'll walk through language features with the example!

This talk was given at the Webcamp Zagreb 2016

Sebastian

October 29, 2016
Tweet

More Decks by Sebastian

Other Decks in Programming

Transcript

  1. “So any team considering Angular2 should consider Dart as well.”

    Joshy Joseph, Google Adwords http://news.dartlang.org/2016/03/the-new-adwords-ui-uses-dart-we-asked.html
  2. Why Dart? • A consistent language • Great standard library

    • Batteries included • General purpose language
  3. A consistent language • Everything is an object • Optional

    static types • Async/Await • Library system
  4. Batteries included • dart: The interpreter • pub: Package manager

    • dartfmt: Opinionated formatter • dartanalyzer: Static code analyzer • dart2js: Transpiler • ...
  5. Why not? • A new language to learn • Hard

    to find experts • Moving target • Small community
  6. Optional types String name = ‘Sebastian’; var firstName = ‘Sebastian’;

    assert(name == firstName); String fullName(String firstName, var lastName) { return firstName + ‘ ‘ + lastName; }
  7. Function arguments String test(String arg1, [String arg2]) { // ...

    } test(‘s1’); test(‘s1’, ‘s2’);
  8. Function arguments String test(String arg1, [String arg2]) { // ...

    } test(‘s1’); test(‘s1’, ‘s2’); String test2(String arg1, {String arg2}) { // ... } test2(‘s1’); test2(‘s1’, arg2: ‘s2’);
  9. Constructors class User2 { String firstName; int age; User2(String firstName,

    int age){ this.firstName = firstName; this.age = age; } }
  10. Implicit Getters/Setters User sebastian = new User(‘Sebastian’, 29); print(sebastian.firstName); //

    Output: ‘Sebastian’ sebastian.age = 32; print(sebastian.age); // Output: ‘32’
  11. Implicit Getters/Setters class User { String _firstName; // private property

    int _age; // private property String get firstName { return _firstName; } void set age(age) { _age = age < 21 ? 0 : age; } }
  12. Implicit Getters/Setters User sebastian = new User(‘Sebastian’, 29); print(sebastian.firstName); //

    Output: ‘Sebastian’ sebastian.age = 32; print(sebastian.age); // Error!
  13. Exceptions void letMeFail() { throw ‘This is my error message’;

    } try { letMeFail(); } on String catch s { print(s); } catch() { print(‘Generic Exception’); }
  14. Async / Await doSomething() async { await longTask(); // ...

    } doSomething2() { longTask().then(() { // … }); }
  15. “So any team considering Angular2 should consider Dart as well.”

    Joshy Joseph, Google Adwords http://news.dartlang.org/2016/03/the-new-adwords-ui-uses-dart-we-asked.html