Top Banner
Haxe Cross-platform in French / Sergei Egorov @bsideup 0
42

Haxe by sergei egorov

Jan 25, 2015

Download

Software

Sergei Egorov

My haxe presentation for DevClub
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Haxe by sergei egorov

HaxeCross-platform in French

/ Sergei Egorov @bsideup

0

Page 2: Haxe by sergei egorov

About meSenior Server Developer at Creative MobileHaxe user since 2008Introduced Haxe in our company

Page 3: Haxe by sergei egorov

What is Haxe?First release in April 2006Open source languageStrictly typedDeveloped by Nicolas Cannasse (Well known in Flash community thanks to MTASC compiler)

Page 4: Haxe by sergei egorov

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

Page 6: Haxe by sergei egorov

Meet my hipster friend

and he don't trust me that Haxe is cool

Page 7: Haxe by sergei egorov

"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

Page 8: Haxe by sergei egorov

Why I need another JavaScript?

Page 9: Haxe by sergei egorov

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!"); }}

Page 10: Haxe by sergei egorov

OOP is so old-school. I want more!

Page 11: Haxe by sergei egorov

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]

Page 12: Haxe by sergei egorov

I don't get it. Anything else?

Page 13: Haxe by sergei egorov

Static extensions?class IntExtender { static public function triple(i:Int) { return i * 3; }}

using IntExtender;

trace(12.triple());

Page 14: Haxe by sergei egorov

Not bad, no need to use prototypes.

Page 15: Haxe by sergei egorov

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); }}

Page 16: Haxe by sergei egorov

Ok. Not so bad. Another JavaScript generator.

Page 17: Haxe by sergei egorov

Not JS only. It's cross-platform!

Page 18: Haxe by sergei egorov

How many languages do you knowwho can be compiled to:

Page 19: Haxe by sergei egorov

JavaScript

Page 20: Haxe by sergei egorov

Java?

Page 21: Haxe by sergei egorov

C/C++?

Page 22: Haxe by sergei egorov

C#?

Page 23: Haxe by sergei egorov

Objective-C?

Page 24: Haxe by sergei egorov

Python?

Page 25: Haxe by sergei egorov

PHP?

Page 26: Haxe by sergei egorov

ActionScript?

Page 27: Haxe by sergei egorov

All of them!

Page 28: Haxe by sergei egorov

Cross-platform Haxe Others

Page 29: Haxe by sergei egorov

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

Page 30: Haxe by sergei egorov

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)");

Page 31: Haxe by sergei egorov

STD lib for each target platformcpp.Libflash.Libjava.Libjs.Libphp.Lib...

Page 32: Haxe by sergei egorov

Nothing is perfect.

Page 33: Haxe by sergei egorov

Yes! So...

Page 34: Haxe by sergei egorov

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:)

Page 35: Haxe by sergei egorov

Haxeat Creative Mobile

Page 36: Haxe by sergei egorov

Drag Racing Social

Page 37: Haxe by sergei egorov

Drag Racing SocialSimulation library port from Java to HaxeMain functionality in gameSame simulation code base for client and serverNot afraid of floating pointGood performance!

Page 38: Haxe by sergei egorov

One more thing

Page 39: Haxe by sergei egorov

Gradle Haxe plugin!Created by me:)Compile Haxe with Gradle build systemBasic haxelib supportMulti-target awareSource code:https://github.com/bsideup/graxe

Page 40: Haxe by sergei egorov

Example configurationhaxe { targets { swf { mainClass "TestSwf" } java { mainClass "TestJava" } }}

dependencies { compile project(":libraryModule") compile haxeLib("tjson", "1.2.3")}

Page 41: Haxe by sergei egorov

Demo

Page 42: Haxe by sergei egorov

Questions?