haxe by sergei egorov
DESCRIPTION
My haxe presentation for DevClubTRANSCRIPT
HaxeCross-platform in French
/ Sergei Egorov @bsideup
0
About meSenior Server Developer at Creative MobileHaxe user since 2008Introduced Haxe in our company
What is Haxe?First release in April 2006Open source languageStrictly typedDeveloped by Nicolas Cannasse (Well known in Flash community thanks to MTASC compiler)
Why Haxe is cool?Cross-platform OOP languageGood syntaxProvides good API for extending languageGenerates sources for target languageBig communityHaxelib - repository for your Haxe libsonline REPL try.haxe.org
Who thinks Haxe is cool?
Meet my hipster friend
and he don't trust me that Haxe is cool
"But why?" I said. Look at it:var arr = [for (i in 0...10) if (i%2==0) i];var value = 1; function myLocalFunction(i) : {num: Int} { return if(i % 2 == 0) { {num : value + i}; } else { {num : value}; };}
trace(myLocalFunction(arr[1]).num); // 3
Why I need another JavaScript?
It's not JS! We have classes:)interface Placeable<T> { public var x:T; public var y:T;}
class Main implements Placeable<Float> { public var x:Float; public var y:Float; public function new() { trace("I'm constructor!"); }}
OOP is so old-school. I want more!
How about abstract types?abstract StringSplitter(Array<String>) { inline function new(a:Array<String>) this = a; @:from static public inline function fromString(s:String) { return new StringSplitter(s.split("")); }}
var splitter:StringSplitter = "Hello";trace(splitter); // [H,e,l,l,o]
I don't get it. Anything else?
Static extensions?class IntExtender { static public function triple(i:Int) { return i * 3; }}
using IntExtender;
trace(12.triple());
Not bad, no need to use prototypes.
We have algebraic data types tooenum Color3 { Red; Green; Blue; Rgb( r : Int, g : Int, b : Int ); Alpha( a : Int, col : Color3 );} function toInt( c : Color3 ) : Int { return switch( c ) { case Red: 0xFF0000; case Green: 0x00FF00; case Blue: 0x0000FF; case Rgb(r,g,b): (r << 16) | (g << 8) | b; case Alpha(a,c): (a << 24) | (toInt(c) & 0xFFFFFF); }}
Ok. Not so bad. Another JavaScript generator.
Not JS only. It's cross-platform!
How many languages do you knowwho can be compiled to:
JavaScript
Java?
C/C++?
C#?
Objective-C?
Python?
PHP?
ActionScript?
All of them!
Cross-platform Haxe Others
Conditional compilation for platform-specific code
#if flash8 // Haxe code specific for flash player 8#elseif flash // Haxe code specific for flash platform (any version)#elseif js // Haxe code specific for javascript plaform#elseif neko // Haxe code specific for neko plaform
Platform-specific magic functions//ActionScript: Valid referenceuntyped __global__["flash.display.DisplayObject"];
// JavaScript: Call codeuntyped __js__("Navigator.plugin[\"Shockwave Flash\"]");
// PHP: value of $_SERVER['REQUEST_METHOD']untyped __var__('_SERVER', 'REQUEST_METHOD') // C#var str:String = "test untyped";untyped __cs__("System.Console.WriteLine(str)"); // Javauntyped __java__("java.lang.System.out.println(str)");
STD lib for each target platformcpp.Libflash.Libjava.Libjs.Libphp.Lib...
Nothing is perfect.
Yes! So...
Haxe shortcomingsNot-so-good IDE support:
Good support in FlashDevelop (Windows only)Limited support in IntelliJ IDEA for all platformsFew other IDEs like FDT
Verbosity (i.e. no short lambdas)Written in OCaml:)
Haxeat Creative Mobile
Drag Racing Social
Drag Racing SocialSimulation library port from Java to HaxeMain functionality in gameSame simulation code base for client and serverNot afraid of floating pointGood performance!
One more thing
Gradle Haxe plugin!Created by me:)Compile Haxe with Gradle build systemBasic haxelib supportMulti-target awareSource code:https://github.com/bsideup/graxe
Example configurationhaxe { targets { swf { mainClass "TestSwf" } java { mainClass "TestJava" } }}
dependencies { compile project(":libraryModule") compile haxeLib("tjson", "1.2.3")}
Demo
Questions?