ZHGDG[7.27]GDL.3~10 Reasons You_ll Love Dart

ZHGDG[7.27]GDL.3~10 Reasons You_ll Love Dart

ZHGDG[7.27]GDL.3
10 Reasons You_ll Love Dart Presentation

6002ee051e03f0b762642ee7fafd111f?s=128

Zoom.Quiet

July 29, 2013
Tweet

Transcript

  1. 10 Reasons You're Going to Love Dart Chris Strom @eee_c

  2. • Browser Language (primarily) • Familiar • Incorporates Lessons Learned

  3. JavaScript • Browser Language (primarily) • Familiar • Incorporates Lessons

    Learned
  4. 10+

  5. -Alan Perlis A language that doesn't affect the way you

    think about programming, is not worth knowing.
  6. Ew... Static Typing

  7. hostile to the open-web non-standard language

  8. Nobody is using it…

  9. Quick Dart Primer: Functions say_hi(name) { return "Hi, ${name}"; }

    say_hi("Bob"); // "Hi, Bob"
  10. Quick Dart Primer: Functions say_hi(name) { return "Hi, ${name}"; }

    say_hi("Bob"); // "Hi, Bob"
  11. say_hi(name) { return "Hi, ${name}"; } say_hi("Bob"); // "Hi, Bob"

    Quick Dart Primer: Functions
  12. Quick Dart Primer: Functions say_hi(name) { return "Hi, ${name}"; }

    say_hi("Bob"); // "Hi, Bob"
  13. say_hi(name) { return "Hi, ${name}"; } say_hi("Bob"); // "Hi, Bob"

    Quick Dart Primer: Functions
  14. say_hi(name) { return "Hi, ${name}"; } say_hi("Bob"); // "Hi, Bob"

    Quick Dart Primer: Functions
  15. say_hi(name) { return "Hi, ${name}"; } say_hi("Bob"); // "Hi, Bob"

    Quick Dart Primer: Functions
  16. Quick Dart Primer: Functions say_hi(name) { return "Hi, ${name}"; }

    say_hi("Bob"); // "Hi, Bob"
  17. Quick Dart Primer: Functions say_hi(name) { return "Hi, ${name}"; }

    say_hi("Bob"); // "Hi, Bob"
  18. Quick Dart Primer: Functions say_hi(name) { return "Hi, ${name}"; }

    say_hi("Bob"); // "Hi, Bob"
  19. Quick Dart Primer: Functions say_hi(name) => "Hi, ${name}"; say_hi("Bob"); //

    "Hi, Bob"
  20. var say_hi = (name) => "Hi, ${name}"; say_hi("Bob"); // "Hi,

    Bob" Quick Dart Primer: Anon. Functions
  21. Oh, Ruby… I ♥ You So Much class Cookie attr_reader

    :number_of_chips def initialize(num) @number_of_chips = num end end c = Cookie.new(1) c.number_of_chips => 1
  22. Oh, Dart… I ♥ You So Much class Cookie {

    var number_of_chips; Cookie(num) { number_of_chips = num; } }
  23. Magic Instance Variables class Cookie { var number_of_chips; Cookie(num) {

    number_of_chips = num; } }
  24. Magic Instance Variables class Cookie { var number_of_chips; Cookie(this.number_of_chips); }

  25. Magic Instance Variables class Cookie { var number_of_chips; Cookie(this.number_of_chips); }

    > var cookie = new Cookie(12); > cookie.number_of_chips; // 12 > cookie.number_of_chips = 25; > cookie.number_of_chips; // 25
  26. Magic Instance Variables class Cookie { var _calories; // ...

    } > var cookie = new Cookie(); > cookie._calories; // Error! > cookie._calories = 25; // Error!
  27. Getters and Setters class Cookie { var _calories; get calories

    => _calories / 3; set calories(v) { _calories = v; } } > var cookie = new Cookie(); > cookie.calories = 300; > cookie.calories; // 100
  28. Optional Parameters class Cookie { var calories; Cookie({calories}) { this.calories

    = calories; } } > c1 = new Cookie(calories: 300); > c2 = new Cookie();
  29. Optional Parameters class Cookie { var calories, number_of_chips; Cookie({ this.calories,

    this.number_of_chips }); } > c1 = new Cookie(calories: 300); > c1.calories; // 300
  30. Optional Parameters class Cookie { var calories, number_of_chips; Cookie({ this.calories,

    this.number_of_chips }); } > c2 = new Cookie(number_of_chips: 9); > c2.number_of_chips; // 9
  31. Optional Parameters class Cookie { var calories, number_of_chips; Cookie({ this.calories,

    this.number_of_chips: 2 }); } > c3 = new Cookie(); > c3.number_of_chips; // 2
  32. Optional Parameters class Cookie { var calories, number_of_chips; Cookie([ this.calories,

    this.number_of_chips]); } > c1 = new Cookie(120, 9); > c2 = new Cookie(120); > c3 = new Cookie();
  33. Method Cascades cookie ..mix_it() ..stir_it() ..bake_it() ..eat_it();

  34. Method Cascades cookie ..calories = 120 ..number_of_chips = 12 ..bake_time

    = 30 ..deliciousness = 42;
  35. Method Cascades bg.style ..position = 'absolute' ..top = '0px' ..left

    = '0px' ..width = "${doc.offsetWidth}px" ..height = "${doc.clientHeight}px" ..backgroundColor = 'black' ..opacity = '0.8' ..zIndex = '1000';
  36. Unit Tests test_create() { group("new DBs", () { setUp(removeFixtures); tearDown(removeFixtures);

    test("creates a new DB", () {/*…*/}); }); }
  37. Unit Tests test_create() { group("new DBs", () { setUp(removeFixtures); tearDown(removeFixtures);

    test("creates a new DB", () {/*…*/}); }); }
  38. Unit Tests // ... test("creates a new DB", () {

    var db = new Dirty('test/test.db'); expect( new File('test/test.db').exists(), equals(true) ); });
  39. test("can write to the DB", () { var db =

    new Dirty('test/test.db'); db['everything'] = {'answer': 42}; db.close(expectAsync0(() { expect( new File('test/test.db').size(), greaterThan(0) ); })); }); Unit Tests
  40. test("can write to the DB", () { var db =

    new Dirty('test/test.db'); db['everything'] = {'answer': 42}; db.close(expectAsync0(() { expect( new File('test/test.db').size(), greaterThan(0) ); })); }); Unit Tests
  41. Client-side Libraries import 'dart:html'; import 'dart:json'; import 'cookie.dart'; main() {

    var cookie = new Cookie(12); }
  42. Client-side Libraries class Cookie { var number_of_chips; Cookie(this.number_of_chips); }

  43. Client-side Libraries library cookies; class Cookie { var number_of_chips; Cookie(this.number_of_chips);

    }
  44. Client-side Libraries import 'dart:html'; import 'dart:json'; import 'cookie.dart'; main() {

    var cookie = new Cookie(12); }
  45. Pub Packages $ cd public/scripts $ cat pubspec.yaml name: killer_app

    dependencies: hipster_mvc: any $ pub install Resolving dependencies... Dependencies installed!
  46. $ cd public/scripts $ cat pubspec.yaml name: killer_app dependencies: hipster_mvc:

    any $ pub install Resolving dependencies... Dependencies installed! Pub Packages
  47. Pub Packages $ cd public/scripts $ cat pubspec.yaml name: killer_app

    dependencies: hipster_mvc: any $ pub install Resolving dependencies... Dependencies installed!
  48. Pub Packages library cookie_model; import 'package:hipster_mvc/hipster_model. dart'; class Cookie extends

    HipsterModel { Cookie(attributes) : super(attributes); }
  49. Pub Packages • pub.dartlang.org • public git repositories • great

    for local dev
  50. Statically Typed Language

  51. Statically Typed Language (but not really)

  52. Statically Typed Language Sneakily

  53. (Not Really) Static Typing class Cookie { var number_of_chips; Cookie(this.number_of_chips);

    }
  54. (Not Really) Static Typing class Cookie { int number_of_chips; Cookie(this.number_of_chips);

    }
  55. (Not Really) Static Typing class Cookie { int number_of_chips; Cookie(this.number_of_chips);

    } var c1 = new Cookie(12); var c2 = new Cookie('salt'); print(""" c1: ${c1.number_of_chips} chips c2: ${c2.number_of_chips} chips""");
  56. (Not Really) Static Typing class Cookie { int number_of_chips; Cookie(this.number_of_chips);

    } c1: 12 chips c2: salt chips
  57. $ dartanalyzer static_typing.dart 'String' is not assignable to 'int' 2:

    var c1 = new Cookie(12); 3: var c2 = new Cookie('salt'); ~~~~~~ (Not Really) Static Typing
  58. Dartdocs $ dartdoc cookie.dart

  59. Dartdocs

  60. Dartdocs /// A yummy, yummy food. class Cookie { ///

    The number of chips in the /// cookie. The more the better. int number_of_chips; /// We do not support cookies /// without chips at this time. Cookie(this.number_of_chips); }
  61. Dartdocs

  62. Dartdocs

  63. Dartdocs Documentation I didn't write

  64. Dartdocs Documentation I didn't write

  65. Dartdocs Class navigation

  66. Dartdocs Search (client-side)

  67. Dartdocs I ♥ Documentation

  68. Dartdocs I ♥ Static Typing

  69. I ♥ Dart

  70. Thanks! Chris Strom @eee_c #pairwithme!!! Buy the book :) Also:

    SPDY, Backbone.js, 3D Game Programming for Kids
  71. Generative Constructors

  72. Operators Overloading

  73. Isolates

  74. Futures