Haxe for Javascripters
Have you tried Haxe yet?
Brendan Graetz
Haxe
Overview
ECMAScript
Community
Haxe to JS
Pros/ Cons
Demo
The ECMAScripts
ECMAScript 3
1st widely implemented Javascript
ECMAScript 4
Failed as a Javascript spec
Implemented in ActionScript 3
ECMAScript 5
2nd widely implemented Javascript
ECMAScript 6
Hot off the presses
Now called ES2015
So ... Haxe ?
inspired by AS3
so, quite ECMAScript-ish
also has elements of OCaml & Java
take Javascript, and add types
Typescript, anyone?
Haxe is not ECMAScript compliant, it is more of a fork/ branch
See this article which enumerates one of the more obvious differences
For a Javascript developer, similar enough for most of it to feel familiar
ES6/ ES7 features are not planned to be implmented, hwoever, many of them have already been included
There are macros for this, if you really want to
Comparing TypeScript and Haxe - which is the better compile to Javascript language?
TypeScript vs Haxe
(Andy Li)
Looking at the Haxe to Javascript compiler in detail
Vanilla Haxe JS
(Phillipe Elsass)
Original mission
Alternative OSS compiler to Flash
Compiler written using OCaml
Beat Adobe's own Flash compiler
Focus
Due to roots, very centred around Game Dev
LudumDare: Dominated by HaxeFlixel
This is beginning to change now
Mentioned on haxe.io ... next minute:
Haxe Foundation
Core contributors to the compiler and the language spec
See @glazou's
critique of the Haxe foundation
Controversy alert: Run like 1-man show
Could learn from the iojs/node foundation
Daniel Glazman sits on one of W3C's committees, and so his opinion carries a lot of weight
However, this talk was very polarising amongst the Haxe community, and many of them reject his point of view
His point that large corporations will only invest in technologies that appear to be governed by a stable committee (or another corporation) still should be considered though, and seeing how NodeJs foundation has recruited comapnies to sit on its board
Read "Regarding Haxe Foundation" in
this heated discussion
Silex Labs
Non profit organisation that promotes OSS
Hosts many meetups & workshops
Organises WWX
Silex labs is not only focussed on Haxe, but many other languages and technologies
Crowdfunding needed to make the conference happen
Needs more of this sort of thing
Where are Haxers now?
(trailing: rest of Europe + US)
Pourtant, toute la documentation est en Anglais
Yet, all the documentation is in English, which is awesome
If I got that wrong, don't blame me - blame Google translate!
Package Manager
npm
is to NodeJs ...
... as haxelib
is to Haxe ...
... but haxelib
is a bit more C-like:
LD_LIBRARY_PATH
(all libs installed globally by default)
haxelib local
allows local installation of libraries
... and now, the killer feature!
Cross-compile
Most languages: Language + Standard Lib
Haxe: Those, plus cross platform APIs
Transpiles to natively compile-able code
VMs or run times are
optional
Awesome - right now:
HTML+JS
C++ --> iOS
C++ --> Android NDK
Java ( --> Android SDK )
Flash
Auto-magic tooling
haxelib install openfl
haxelib run openfl setup
# Unleash the dragons!
openfl setup android
# {android,ios,html5,flash,linux,mac,windows,blackberry,tizen}
(Same feeling as npm i -g react-native-cli
for the first time)
OpenFL is one of the more popular haxelibs out there
It's a framework, used primarily to compile games (Flash API) that run many target devices
Andy Li's talk at a recent London Meetup :
There are over 300 transpile to Javascript languages/ platforms ...
It is a balancing act, where you maximise the pros and minimise the cons ...
Haxe has a very good value proposition from this point of view
(I'm paraphrasing)
Pros
Cons
Static type checking + type inference
Lose the flexibility of object literals
Idiomatic JS
==
instead of ===
non-JS targets as well
Transpile adds extra build step
Functional programming
Classes everywhere
Compile-time optimisation
Super fast compiler
Mature - 2005
Macros
Haxe itself ensures strict equality, however the JS it outputs uses ==
instead of ===
Haxe satisfies both sides of the camp in the functional vs OOP thing, so it really is your preference
On the matter of being used to interpreted languages. Haxe as a language has proven itself to be very extensible. JS devs who prefer to write Coffeescript might enjoy Raxe , which is Haxe with ruby-inspired syntax
JS only
JS + Android + iOS
Typescript
Haxe
Coffeescript
PhoneGap
many more...
React Native
NativeScript
Emscripten
GWT & LLVM
... many more
Cross-compilation is the reason to try Haxe
Khan academy recently did a comparison of
code sharing strategies , because:
*"Reimplementing the same thing multiple times is error-prone, time-consuming, and demoralizing. But the cure might be worse than the disease."*
... so I felt compelled to add a column for Haxe :
Go check out the document, some of the pros and cons listed here are there too
People
Haxe <--> Javascript expert
Super interesting articles
Summary
Javascript-ish syntax
Game Dev awesomesauce community
Best-in-class cross compilation
Try Haxe
try.haxe.org
... like, in your browser
... like, right now