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. Bullseye: An
    introduction to Dart
    Webcamp Zagreb 2016
    @Sgoettschkes
    https://static.pexels.com/photos/21300/pexels-photo.jpg

    View full-size slide

  2. “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

    View full-size slide

  3. Why Dart?
    https://static.pexels.com/photos/59628/pexels-photo-59628.jpeg

    View full-size slide

  4. Why Dart?
    ● A consistent language
    ● Great standard library
    ● Batteries included
    ● General purpose language

    View full-size slide

  5. A consistent language
    ● Everything is an object
    ● Optional static types
    ● Async/Await
    ● Library system

    View full-size slide

  6. Great standard library
    ● dart:core
    ● dart:async
    ● dart:math
    ● dart:html or dart:io
    ● dart:convert

    View full-size slide

  7. Batteries included
    ● dart: The interpreter
    ● pub: Package manager
    ● dartfmt: Opinionated formatter
    ● dartanalyzer: Static code analyzer
    ● dart2js: Transpiler
    ● ...

    View full-size slide

  8. General purpose language
    ● Client-Side (AngularDart / PolymerDart)
    ● Server-Side (rpc / redstone)
    ● Mobile (fluffer)
    ● ...

    View full-size slide

  9. Why not?
    ● A new language to learn
    ● Hard to find experts
    ● Moving target
    ● Small community

    View full-size slide

  10. Language Features
    https://www.dropbox.com/s/tfrndnh2i883wbs/289H.jpg?dl=1

    View full-size slide

  11. Optional types
    String name = ‘Sebastian’;
    var firstName = ‘Sebastian’;
    assert(name == firstName);

    View full-size slide

  12. Optional types
    String name = ‘Sebastian’;
    var firstName = ‘Sebastian’;
    assert(name == firstName);
    String fullName(String firstName, var lastName) {
    return firstName + ‘ ‘ + lastName;
    }

    View full-size slide

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

    View full-size slide

  14. 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’);

    View full-size slide

  15. Constructors
    class User {
    String firstName;
    int age;
    User(this.firstName, this.age);
    }

    View full-size slide

  16. Constructors
    class User2 {
    String firstName;
    int age;
    User2(String firstName, int age){
    this.firstName = firstName;
    this.age = age;
    }
    }

    View full-size slide

  17. Implicit Getters/Setters
    User sebastian = new User(‘Sebastian’, 29);
    print(sebastian.firstName); // Output: ‘Sebastian’
    sebastian.age = 32;
    print(sebastian.age); // Output: ‘32’

    View full-size slide

  18. 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;
    }
    }

    View full-size slide

  19. Implicit Getters/Setters
    User sebastian = new User(‘Sebastian’, 29);
    print(sebastian.firstName); // Output: ‘Sebastian’
    sebastian.age = 32;
    print(sebastian.age); // Error!

    View full-size slide

  20. Exceptions
    void letMeFail() {
    throw ‘This is my error message’;
    }

    View full-size slide

  21. Exceptions
    void letMeFail() {
    throw ‘This is my error message’;
    }
    try {
    letMeFail();
    } on String catch s {
    print(s);
    } catch() {
    print(‘Generic Exception’);
    }

    View full-size slide

  22. String interpolation
    String fullName(firstName, lastName) {
    return ‘${firstName} ${lastName}’;
    }

    View full-size slide

  23. String interpolation
    String fullName(firstName, lastName) {
    return ‘${firstName} ${lastName}’;
    }
    print(‘${fullName(‘Sebastian’, ’Göttschkes’)}’);

    View full-size slide

  24. Async / Await
    doSomething() async {
    await longTask();
    // ...
    }

    View full-size slide

  25. Async / Await
    doSomething() async {
    await longTask();
    // ...
    }
    doSomething2() {
    longTask().then(() {
    // …
    });
    }

    View full-size slide

  26. But what about ...

    View full-size slide

  27. http://pixabay.com/static/uploads/photo/2010/12/10/08/salad-1105_640.jpg

    View full-size slide

  28. “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

    View full-size slide

  29. https://www.dropbox.com/s/6z5aiwa8l09g2pa/86H.jpg

    View full-size slide

  30. https://joind.in/talk/3c5ab

    View full-size slide