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 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 Slide

  3. View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  15. 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 Slide

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

    View Slide

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

    View Slide

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

    View Slide

  19. 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 Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  27. But what about ...

    View Slide

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

    View Slide

  29. View Slide

  30. View Slide

  31. “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 Slide

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

    View Slide

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

    View Slide