Nicolas Cannasse
@ncannasse
WWX 2013
haxelib
repository
In 2.x:
class Example { public var name(default,setName) : String; public var age(getAge,setAge) : Int; }
In 3.x:
class Example { public var name(default,set) : String; @:isField public var age(get,set) : Int; function set_name(v) { //.... } }
In 2.x:
function onClicked(item:Item) { } //... for( item in allItems ) item.elt.click(callback(onClicked,item));
In 3.x:
for( item in allItems ) item.elt.click(onClicked.bind(item));
More use cases:
function div(x,y) return x / y; div(1,2); var invert = div.bind(1); invert(2); var percent = div.bind(_,100); percent(5);
In 2.x:
var byName : Hash<MyObject> = new Hash(); var byId : IntHash<MyObject> = new IntHash();
In 3.x:
var byName : Map<String,MyObject> = new Map(); var byId : Map<Int,MyObject> = new Map(); // but also: var objectMap : Map<MyObject,MyOtherObject> = new Map(); var enumMap : Map<MyEnum,Something> = new Map();
Literal maps:
[ "Hello" => "World", "WWX" => "Rocks!" ]
(neko|cpp|php).FileSystem -> sys.FileSystem (neko|cpp|php).io -> sys.io class Sys // print(), args(), etc.
haxe.crypto
package (Md5, Sha1, etc.)
haxe.ds
package for datastructures (GenericStack, Vector, WeakMap, ...)
haxe.Int32
(Neko 2.0+ has native int32 support)
var name = "WWX"; 'Hello $name!'; 'Hello ${name.toLowerCase()}!';
Std.format
)-D format-warning
when porting code using it.enum E { Leaf; Value( v : Int ); Tree( left : E, right : E ); }
Different cases:
switch( e ) { case Leaf: case Value(0): case Value(x) if( x > 0 ): /* guard */ case Tree(Leaf,Value(x)): case all: throw "Error "+all; }
In 2.x:
var arr = new Array(); for( i in 0...10 ) arr.push(i);
In 3.x:
var arr = [for( i in 0...10 ) i];
Inner loops and filters:
var arr = [ for( x in 0...10 ) for( y in 0...10 ) if( x+y < 10 ) x*y; ];
Map comprenhension:
var m = [for( x in 0...10 ) x => x*x];
abstract Meter(Int) { public function new(i:Int) this = i; public function toInt() : Int return this; } abstract Kilometer(Float) { public function new(i:Float) this = i; public function toInt() : Float return this; }
var m = new Meter(1000); var k = new Kilometer(1.0);
Compiles to:
var m = 1000; var k = 1.0;
Auto-cast from:
abstract Meter(Int) { //... @:from static inline function fromInt(i) { return new Meter(i); } }
Now allows:
var x : Meter = 10;
Auto-cast to:
abstract Meter(Int) { //... @:to inline function toKilometer() { return new Kilometer(this/1000.0); } }
var x : Kilometer = new Meter(100);
Compiles to:
var x = 0.1;
abstract Meter(Int) { //... @:op(A + B) static function add(a:Meter,b:Meter):Meter; }
Map
implementation)Our partners:
Our plans:
std
SpecificationA new way to define it:
api.haxe.org
The way we work:
Done with http://github.com/ncannasse/hxslides