0
Haxe: What Makes It Cool
 Dev Ideas, episode 1


Brought to you by Chicken Wing Software
Hello, my name is...
 Eddie Sullivan
Founder, Chicken Wing Software
www.chickenwingsw.com
www.devideas.com
See also: UX Id...
Haxe
     ≈
    JavaScript
               +   static types
                               +   Java-style classes
         ...
Haxe is like JavaScript
(really ActionScript)
 Similar syntax and keywords (like function)
 Entire DOM-tree available
 Fla...
DOM example
                             Example:
// Change an HTML element to a random color.
static function changeToRan...
Haxe is like... Java
                             Example:
import js.Lib;
import StringTools;

class HaxeExample {
    // ...
Similarities to Java
 Java-style classes & inheritance
 Statically & strongly typed
 Single inheritance & interfaces
 Can ...
Some familiar keywords
      if/else          do/while
      true/false       new
      var              this
      try/ca...
Haxe is like... ML

 Type inference
     Types with less typing
 var x = "hello"; // x is a String
 var y:String;    // y ...
Haxe's enums
Defining the enum:
enum Command {
  sit;
  speak(word:String);
  move(x:Int, y:Int);
}
// ... inside a functi...
Haxe's switch
Using the enum:
// ... inside a function:
switch (cmd) {
  case sit:
    this.sitting = true;
    case speak...
Haxe's for
More like "foreach" in C#
// ... inside a function:

var names = ['Ed', 'Fred', 'Ned', 'Ted'];
// Could have wr...
Other features
 Local functions/closures
 Type parameters (generics)
 Exceptions
 Dynamic & untyped values
 "Batteries Inc...
Flash example (part 1)
import flash.display.Sprite;
import caurina.transitions.Tweener;
class Happy extends Sprite
{
    p...
Flash example (part 2)
   // ... continued from last slide
   public function start()
   {
       var that = this;
       ...
Flash example (part 3)
import flash.external.ExternalInterface;
import flash.Lib;

class Main
{
  static var happy = new H...
Flash example (part 4)
What it looks like:


Stop   -   Start
The Haxe Community
 Mailing list
 Forum
 Wiki
 Libraries / haxelib (lib.haxe.org)
 FlashDevelop
 More...
Thank you!
Chicken Wing Software - chickenwingsw.com
Dev Ideas - devideas.com
Follow me on Twitter: @eddieSullivan
Sign up...
Upcoming SlideShare
Loading in...5
×

Haxe: What Makes It Cool

1,619

Published on

Haxe is a relatively newcomer in the field of programming languages, but it has already developed a following and a large user base. Haxe's claim to fame is as an open source alternative to the Flash compiler, but it can be used for a whole lot more.

In this presentation, Eddie Sullivan of Chicken Wing Software gives a quick introduction to the language and talks about what makes it interesting and useful, and what makes it worth learning. Accompanying video at http://devideas.com

Published in: Technology
1 Comment
1 Like
Statistics
Notes
No Downloads
Views
Total Views
1,619
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
13
Comments
1
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "Haxe: What Makes It Cool"

  1. 1. Haxe: What Makes It Cool Dev Ideas, episode 1 Brought to you by Chicken Wing Software
  2. 2. Hello, my name is... Eddie Sullivan Founder, Chicken Wing Software www.chickenwingsw.com www.devideas.com See also: UX Ideas
  3. 3. Haxe ≈ JavaScript + static types + Java-style classes + type inference + algebraic types www.haxe.org Compiles to JavaScript, Flash, NekoVM, PHP, C++ Standard library + platform libs + RPC
  4. 4. Haxe is like JavaScript (really ActionScript) Similar syntax and keywords (like function) Entire DOM-tree available Flash API available (no timeline) Can compile to .js file Can compile to .swf file Closures Regular expressions
  5. 5. DOM example Example: // Change an HTML element to a random color. static function changeToRandomColor(id) { var el = Lib.document.getElementById(id); var color = '#' + StringTools.hex(Std.random(0x1000000), 6); el.style.backgroundColor = color; }
  6. 6. Haxe is like... Java Example: import js.Lib; import StringTools; class HaxeExample { // Required "main" function - called at startup. static function main() { } // Change an HTML element to a random color. static function changeToRandomColor(id) { var el = Lib.document.getElementById(id); var color = '#' + StringTools.hex(Std.random(0x1000000), 6); el.style.backgroundColor = color; } }
  7. 7. Similarities to Java Java-style classes & inheritance Statically & strongly typed Single inheritance & interfaces Can compile to NekoVM, PHP, or C++
  8. 8. Some familiar keywords if/else do/while true/false new var this try/catch finally return switch* enum* for* * Different behavior
  9. 9. Haxe is like... ML Type inference Types with less typing var x = "hello"; // x is a String var y:String; // y is also a String x = 3; // ERROR! Algebraic types (With enum and switch)
  10. 10. Haxe's enums Defining the enum: enum Command { sit; speak(word:String); move(x:Int, y:Int); } // ... inside a function var cmd = Command.speak("Arf!");
  11. 11. Haxe's switch Using the enum: // ... inside a function: switch (cmd) { case sit: this.sitting = true; case speak(text): trace(text); case move(x, y): this.location = new Point(x, y); }
  12. 12. Haxe's for More like "foreach" in C# // ... inside a function: var names = ['Ed', 'Fred', 'Ned', 'Ted']; // Could have written: // var names:Array<String> = ... for(name in names) { trace("Hello " + name); }
  13. 13. Other features Local functions/closures Type parameters (generics) Exceptions Dynamic & untyped values "Batteries Included" Remoting XML parsing/validation Sandboxing ...and much more!
  14. 14. Flash example (part 1) import flash.display.Sprite; import caurina.transitions.Tweener; class Happy extends Sprite { public function new(size:Float = 50) { super(); graphics.lineStyle(1.0, 0x000000); graphics.beginFill(0xffff00); graphics.drawCircle(0, 0, size); graphics.endFill(); graphics.moveTo(size * 0.3, size * 0.3); graphics.curveTo(0, size * 0.75, -size * 0.3, size * 0.3); graphics.drawCircle(-size * 0.225, -size * 0.3, size * 0.1); graphics.drawCircle(size * 0.225, -size * 0.3, size * 0.1); } // class continues on next slide...
  15. 15. Flash example (part 2) // ... continued from last slide public function start() { var that = this; Tweener.addTween(this, { rotation:360, time:2, transition:"linear", onComplete: start } ); Tweener.addTween(this, { scaleX:.75, scaleY:.75, time:1 }); Tweener.addTween(this, { scaleX:1, scaleY:1, time:1, delay:1 } ); } public function stop() { Tweener.removeTweens(this); } } // End of class Happy
  16. 16. Flash example (part 3) import flash.external.ExternalInterface; import flash.Lib; class Main { static var happy = new Happy(25.0); static function main() { happy.x = 50; happy.y = 50; Lib.current.addChild(happy); ExternalInterface.addCallback("startHappy", happy.start); ExternalInterface.addCallback("stopHappy", happy.stop); happy.start(); } }
  17. 17. Flash example (part 4) What it looks like: Stop - Start
  18. 18. The Haxe Community Mailing list Forum Wiki Libraries / haxelib (lib.haxe.org) FlashDevelop More...
  19. 19. Thank you! Chicken Wing Software - chickenwingsw.com Dev Ideas - devideas.com Follow me on Twitter: @eddieSullivan Sign up for the newsletter to hear what's coming next UX Ideas - uxideas.com
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×