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

The Web Beyond JavaScript - ScanDev 2012, Gothenburg

The Web Beyond JavaScript - ScanDev 2012, Gothenburg

Jakob Mattsson

April 23, 2012
Tweet

More Decks by Jakob Mattsson

Other Decks in Programming

Transcript

  1. CoffeeScript is a little language that compiles into JavaScript. Underneath

    all those awkward braces and semicolons, JavaScript has always had a gorgeous object model at its heart. CoffeeScript is an attempt to expose the good parts of JavaScript in a simple way. The golden rule of CoffeeScript is: "It's just JavaScript"
  2. number = 42 opposite = true var number, opposite; number

    = 42; opposite = true; CoffeeScript JavaScript
  3. number = -42 if opposite var number; if (opposite) {

    number = -42; } CoffeeScript JavaScript
  4. square = (x) -> x * x var square; square

    = function(x) { return x * x; }; CoffeeScript JavaScript
  5. list = [ 1, 0, 1 0, 1, 0 1,

    0, 1 ] var list; list = [1, 0, 1, 0, 1, 0, 1, 0, 1]; CoffeeScript JavaScript
  6. math = root: Math.sqrt square: square cube: (x) -> x

    * square x var math; math = { root: Math.sqrt, square: square, cube: function(x) { return x * square(x); } }; CoffeeScript JavaScript
  7. race = (winner, runners...) -> print winner, runners var race,

    __slice = [].slice; race = function() { var runners, winner; winner = arguments[0], runners = 2 <= arguments.length ? __slice.call(arguments, 1) : []; return print(winner, runners); }; CoffeeScript JavaScript
  8. alert "I knew it!" if elvis? if (typeof elvis !==

    "undefined" && elvis !== null) { alert("I knew it!"); } CoffeeScript JavaScript
  9. qs = (math.cube num for num in list) var qs,

    num; qs = (function() { var _i, _len, _results; _results = []; for (_i = 0, _len = list.length; _i < _len; _i++) { num = list[_i]; _results.push(math.cube(num)); } return _results; })(); CoffeeScript JavaScript
  10. ”Writing a web app can be lots of fun, especially

    at the beginning when you experience instant gratification: code, reload, repeat.” ”Unfortunately, finishing and maintaining a web app are not so fun. JavaScript is great for small scripts, and it has the performance chops to run large apps. But when a script evolves into a large web app, debugging and modifying that app can be a nightmare, especially when you have a large team.” ”Enter Dart, an open-source project that aims to enable developers to build more complex, highly performant apps for the modern web.”
  11. hi.dart #import('dart:html'); main() { document.query('#status').text = 'Hi, Dart'; } hi.html

    ... <h2 id="status"></h2> <script type="application/dart" src="hi.dart"></script> <!-- If the browser doesn't have an embedded Dart VM, you can compile Dart code to JavaScript. --> <script type="text/javascript" src="hi.dart.js"></script> ...
  12. class Point { Point(this.x, this.y); distanceTo(other) { var dx =

    x - other.x; var dy = y - other.y; return Math.sqrt(dx * dx + dy * dy); } var x, y; } main() { var p = new Point(2, 3); var q = new Point(3, 4); print('distance from p to q = ${p.distanceTo(q)}'); }
  13. class Point { Point(this.x, this.y); num distanceTo(Point other) { num

    dx = x - other.x; num dy = y - other.y; return Math.sqrt(dx * dx + dy * dy); } num x, y; } main() { Point p = new Point(2, 3); Point q = new Point(3, 4); print('distance from p to q = ${p.distanceTo(q)}'); }
  14. main() { print(new List() is List<Object>); print(new List() is List<Dynamic>);

    print(new List<String>() is List<Object>); print(new List<Object>() is! List<String>); print(new List<String>() is! List<int>); print(new List<String>() is List); print(new List() is List<String>); }
  15. #import("dart:html"); main() { // Find an element. var elem =

    document.query("#id"); // Handle events. elem.on.click.add((event) => print('click!')); // Set an attribute. elem.attributes['name'] = 'value'; // Add a child element. elem.elements.add(new Element.tag("p")); // Add a CSS class to each child element. elem.elements.forEach((e) => e.classes.add("important")); }
  16. 1. Languages ARE different 2. Less code, less bugs 3.

    Higher level = productivity 4. Easy to spot less power
  17. WHAT IF ONLY HAVE LITTLE IDEA? SMASH IDEA. THROW AWAY

    DETAIL. THROW AWAY FEATURE. THROW AWAY CAN'T. INSIDE LITTLE IDEA IS BIG PROBLEM HELD DOWN BY CAN'T. SET IT FREE. VISION IS SOLVE PROBLEM NO ONE ELSE SEE.
  18. list.select { |x| x > 0 } filter (> 0)

    list list.filter(function(x) { return x > 0 })
  19. v = a + b unless x > y =>

    (x > y).unless(v = a + b)