
HaXe - Code Once. Deploy Everywhere. - radagaisus
http://haxe.org/
======
bcrescimanno
Ah, "code once. deploy everywhere." Few examples of marketing to engineers
spark quite the same level of skepticism as this oft-repeated claim.

Ignoring, for a moment, the complexity of deploying software across multiple
platforms, it's important to remember the multiple form-factor problem. The
same software doesn't work from a user's standpoint on multiple platforms if
the UI isn't correct for that device. The best example I can give is "mobile
versions" of sites and apps, clearly targeted at the form factor of a phone,
being delivered to a 10" tablet. It's crappy.

Bring in the obvious elephant in the room of the number of times this claim
has been made from an engineering standpoint and truly failed to deliver, and
I yawn every time HaXe is mentioned.

~~~
GavinB
<http://unity3d.com/>

Yes, you have to make allowances for the actual differences between platforms
(physical buttons, screen sizes, input methods), but the rest of the code
deploys extremely well across platforms. When moving between platforms, you
only have to rewrite the pieces that you actually want to be different.

~~~
dirtyaura
Unity is great for a restricted problem space: applications that almost fully
define their own GUI, namely games.

A truly harder cross-platform problem is to abstract access to OS GUI in
usable way.

------
emmett
We use HaXe at Justin.tv.

It has some very nice points, but "code once, deploy everywhere" is
ridiculous. So many of the crucial APIs are platform dependent that there is
absolutely no way your HaXe application is going to be portable.

~~~
reitzensteinm
Agreed - my Haxe games run on iPhone, PC, Mac and Flash from the same code
base. It's way less work than it would be rewriting them, but it's certainly
not a panacea.

However, the NME project (<http://code.google.com/p/nekonme/>) is getting
pretty good; it emulates the Flash APIs on other platforms. Great for games;
probably not usable for the kinds of stuff you do at Justin.tv.

~~~
reitzensteinm
I should mention too that if anyone's interested in Haxe and would like to
talk to me for a few minutes about my experience porting the games at
<http://www.bigblockgames.com> and the feasibility of swapping to it from your
current solution, hit me up at michael@bigblockgames.com.

I don't do contract or consulting work, so you don't have to worry about me
trying to sell you something. :)

~~~
ramanujan
Would you be so kind as to post that experience here?

~~~
reitzensteinm
Sure!

* The Haxe C++ output is very solid. Sometimes there are compiler errors that you have to reverse engineer, like for when you use a try{} without a catch{}, which is valid in Haxe, but throws an error in C++. It's relatively easy though; the C++ output contains which haxe file and line number each line is from, and it has never taken more than a minute or two to figure out what's going on.

There has only been one logic error I've experienced - Haxe guarantees that
arugments of a function are called left to right (i.e. something( readbyte(),
readbyte() );), but of course C++ does not. Other than that, as far as the
core compiler and code generation goes, if it compiles, the generated code is
sound.

* Use NekoNME - bootstrapping on the iPhone without it would require a whole bunch of work. It is an API compatibility layer with Flash, and most basic stuff is replicated. So you code against the Flash APIs, and it spits out a native app on the iPhone, etc. That said, call as few of the Flash APIs as possible; roll stuff by hand, because they kind of suck.

* The garbage collector is quite slow, especially on the iPhone. So you have to be careful about the number of objects you've got in flight, even/especially strings. I don't keep Black Market's story in memory even on the PC version of the game because of this.

* The C++ generated code is very very fast. Though of course some optimisations aren't possible, like creating vectors on the stack, so for example the Haxe Box2d port is slower than the original C++ version of Box2D (I had to use pooled Vectors in Super Goblin).

* If you're making something using 2D graphics, catering to the myriad of display resolutions is going to suck. But that's not a function of Haxe.

* Similarly, you end up doing a whole bunch of work per platform anyway; stuff like putting in app purchasing into the iPhone apps required (at least when I did it) hacking it into the native sections of the NME libraries (a pain, but doable).

* Checkout NME once, and stop updating when it's working well - it breaks often, and is in constant development.

* That said, if you're a hacker, get commit access to NekoNME. If you commit solid changes back they'll love the extra help, and you're likely to want to add some missing features (not as many these days as there were when I did it a year ago).

Now that Unity3D supports Flash, my next game is actually going to be written
in that (see <http://www.underthegarden.com>). However, if Haxe fits your
needs (eg write your website backend, Javascript, SWF, iPhone app, PC
downloadable all from the _same codebase_ ), it's solid and will likely be
around for a long time; there'll be some teething pain, but it isn't a lemon
technology wise.

The reason I suggested people email me is so I can help figure out if it
actually does fit their use case!

------
georgemcbay
I became a huge fan of haxe when I was working at chumby industries and was
limited by the firmware to working on AVM1/ActionScript 2 projects. haxe
allowed me to use a much more modern language with far better features (eg.
compile time macros, inline functions) than AS2 allowed even while hitting the
same VM.

It is a really fantastic language for many different platforms and I
definitely recommend checking it out.

~~~
rabidsnail
1\. While haxe has macros, they're like ocaml macros not like lisp macros. You
can write a function that takes an ast and returns an ast, but because the
language isn't homoiconic it feels a lot more like working with dom than like
macros in lisp.

2\. as2 is a superset of javascript, so it also has inline functions.

3\. Having worked in haxe quite a bit, I found that the fancy type system got
in the way more than it helped. I can't think of one case where it caught a
bug, but I do have memories of spending hours writing typedefs and casting
things to Dynamic.

4\. You can't really target multiple platforms in practice, because nearly
everything you might want to do depends on host-specific features. A multi
platform codebase would be riddled with "if (flash) { } else if (c++) { } else
if (javascript) { ...".

~~~
georgemcbay
1\. True, but whether or not this is good or bad is subjective.

2\. It (AS2 & JS) has functions as a first class type that you can define
anywhere, but it does not have inline functions in the commonly accepted C/C++
sense of the definition. Actual inline function support as included in haxe
can be hugely important on devices with underpowered CPUs since making a
function call has significant overhead in ActionScript when you are running on
a dinky ARMv5 core. With inline functions there is no function call thus no
overhead (at the cost of making the 'compiled' code larger, which is often a
perfectly fine tradeoff).

3\. I love the type system, so again I guess this is subjective.

4\. There is some truth to this but it is easy to encapsulate code that has to
be platform aware (generally UI stuff) into libraries and then keep your
primary app code platform independent.

~~~
andrewem
As to #2, I think georgemcbay is talking about where the contents of a short
function can be copied into the place where it's called (as with the 'inline'
keyword in C or C++), thus avoiding the overhead of a function call [1],
whereas it sounds like rabidsnail is talking about inner or nested functions,
which you can do in JavaScript [2].

[1] <http://en.wikipedia.org/wiki/JavaScript#Functional> [2]
<http://en.wikipedia.org/wiki/Inline_function>

------
singmajesty
The "deploy everywhere" saying may feel a bit tired, but before you hate on
haXe before having given it a try, NME is a perfect example of what's
possible.

I recently wrote a haXe version of "Pirate Pig", a sample game originally
written for Enyo in JavaScript. It took me about a day of work to write, and
it went straight to webOS, Android, Windows, Linux, Linux 64-bit, Flash, Mac
and the iOS simulator.

It would have gone to an actual iOS device, too, but I was too lazy to pull
out my iPod Touch.

If you are interested, please feel free to view the game online, in the webOS
App Catalog, Android Market or downloadable. All the source code and assets
are available, too:

[http://www.joshuagranick.com/blog/2012/02/22/nme-game-
exampl...](http://www.joshuagranick.com/blog/2012/02/22/nme-game-example-
pirate-pig/)

I am very thankful for haXe, which makes the NME project possible. The great
part is that it really works.

------
cromwellian
Another option, if you're a Java programmer and want to reuse existing Java
libraries you've written: <http://code.google.com/p/playn/> which is the
library initially developed to port Angry Birds to HTML5 (although it's true
purpose was to allow Web and Android simultaneous development)

This is a multiplatform API for 2D games. It runs as native Dalvik code on
Android with a GL backend. On the Web, it runs as JS using GWT for
compilation, and either a Canvas or a WebGL backend. For flash, it uses the
<http://code.google.com/p/gwt-flash> addon for the GWT compiler to produce
SWFs. For iOS, it uses iKVM to run Java bytecode on Monotouch. I believe the
same code can also run on the XBox and perhaps Windows phone. Box2D is
builtin.

See <http://www.youtube.com/watch?v=VtwUyu7UzcM> for
<http://www.youtube.com/watch?v=F_sbusEUz5w> for a longer presentation I did
at Google I/O.

------
wensing
The Stormpulse map was originally written in AS2 by yours truly. We recently
moved it over to haXe and are now generating a .swf and an iOS app from the
same codebase. I should say by "we moved it over" I mean an MIT Media Lab PhD.
No way could I have figured out how to manage haXe/NME/X Code the way he did
to pull it off. But it does work. The biggest work left is to make the iOS app
feel like a proper iOS app rather than the Flash app on an iPad.

------
srid68
Why is there so much skepticism in this. I am also trying to develop something
like this by creating a embedded in-process web (resource) server ever where
(android/iphone/wp7*/linux/win/osx), then we need to use web technology using
jquery mobile with backend rpc to develop the application which should make it
cross platform as well native deployed. I am developing this to simplify my
clients cross platform headache. Sometimes i wonder why there is no product in
the market which can do this, which will make my life easier.

Music had 7 symbols and they have perfect interoperability, Software has 2
symbols and interoperability is a dream.

~~~
chc
Software has two symbols? I'm not sure what the analogy is, but the best I can
think of would be either opcodes or functions, and pretty much everybody has a
lot more than two.

~~~
srid68
What i meant was software is based on binary

~~~
tylerlh

      0110100101100110001000000111100101101111011101010010000001100011011000010110111000100000011101000111001001100001011011100111001101101100011000010111010001100101001000000111010001101000011010010111001100100000011101110110100101110100011010000110111101110101011101000010000001101100011011110110111101101011011010010110111001100111001000000110100101110100001000000111010101110000001011000010000001110100011010000110010101101110001000000110100100100111011011000110110000100000011000100110010101101100011010010110010101110110011001010010000001111001011011110111010100100000011010110110111001101111011101110010000001110111011010000110000101110100001000000111100101101111011101010010011101110010011001010010000001110100011000010110110001101011011010010110111001100111001000000110000101100010011011110111010101110100
    

;)

~~~
johns
mind putting a space in that comment? you're breaking the layout

~~~
tylerlh
would be glad to if i were able to edit it. my apologies :|

------
jxcole
Having been writing in Haxe for a long time, I think the "Code once deploy
everwhere" line is an exaggeration. However, it is a nice framework and has
some advantages. In Haxe, you can easily break out into the native language
with c-like # compiler directives, so you can do #if platform=ipod. Now, this
isn't a perfect solution but it does mean that you can keep a good portion of
your code the same source which could save you some time. For certain elements
like the UI, though, you probably have to write a custom version for each
platform no matter what programming language you use.

------
jamesu
I've used HaXe in a few projects. Its a nice abstraction with strong typing
and so on which helps with larger code bases. Combined with NME it is very
powerful: one can compile code for html5, flash, ios, and android with little
to no modification.

My only criticism would be the 32bit integer handling in the neko target. I'm
not sure if its changed recently, but the last time i used it i had to wrap
all operations in "Int32.<operation>(<int32 object>)" function calls which to
me was a completely braindead solution.

------
lignuist
I really hope, HaXe gets a JVM compile target one day. In my opinion that
would make it a perfect language for writing libraries for a large number of
problems for a big audience.

~~~
nkvoll
<http://haxe.org/doc/intro> says "C# and Java targets are coming soon!", and
links to the following tweet:
<http://twitter.com/cwaneck/status/15486381623091200>, which is dated 16.
December 2010.

In other words, I wouldn't get my hopes up :/

------
aritraghosh007
Another programming language which claims to improve productivity by reducing
multi-platform portability. Java starter this revolution , by quoting "Write
Once , Run Anywhere". That phrase has seriously taken a huge leap today and
has been used in all sorts of context.

If I start learning this language , I am not sure if I am actually getting the
full benefit of what a Java/Python provides. I am not convinced until I
actually see a production ready solution.

------
happywolf
After so many years and so many promises like "Write Once and Run Everywhere"
and "Framework that solves all your <you name it> problems", now I will only
give a language/framework more attention after it is used commercially. What I
have in mind are: Go, Lift, D, HaXe, and Scala. But I admit I am not tracking
these closely, so my understanding could be wrong.

------
fufulabs
So what would be the perfect requirements for HaXe to make sense? (i.e. target
desktop + iOS for a game)

------
mkramlich
"multi-platform. code once. deploy everywhere."

wow, that claim makes me feel old. i've lost track of how many existing/legacy
ways we have to write once, deploy anywhere, multi-platform apps. it's like
what they say about the great thing about universal ultimate standards: there
are so many to choose from!

~~~
troymc
Indeed, this was the promise of C, and it was largely realized: there are C
compilers for almost every platform. (You can even use Emscripten to "compile"
C to JavaScript, but don't expect miracles.)

~~~
malkia
I think there was no promise of C. There were two guys that needed somewhat
portable compiler to avoid tying them to one system for their ubiquitous by
now operating system.

Kernighan, Richie, UNIX and C.

Or to take more lighthearted - If there really was promise, there would've not
been need for a preprocessor.

~~~
ternaryoperator
That's right, And even putting aside the preprocessor, prior to C89, C was a
mess portability-wise. (Actually, even after C89, portability was still
frustrated by the problem of the varying size of ints.) Ritchie designed C to
get above the assembly level so that portability would be possible. But it was
certainly not attained until much later.

------
ktizo
Have been writing swf with haXe ever since AS2, I use it with jedit, it is
awesome and Nicolas Cannasse is a god.

------
Radzell
As long as is not javascript i am ok with it. It look kind of like c# or java
which i like though.

------
DasIch
If they would have something that is worth being called documentation I might
have actually taken this seriously.

~~~
EmmanuelOga
Like the gigantic wiki?

<http://haxe.org/doc>

Or the API docs?

<http://haxe.org/api>

Or maybe you rather reading a book?

[http://www.amazon.com/Professional-haXe-Neko-
Programmer/dp/0...](http://www.amazon.com/Professional-haXe-Neko-
Programmer/dp/0470122137)

[http://www.amazon.com/haXe-Beginners-Guide-Benjamin-
Dasnois/...](http://www.amazon.com/haXe-Beginners-Guide-Benjamin-
Dasnois/dp/1849512566)

~~~
lexoyo
But the libraries are what makes haXe so powerful, and they clearly do lack
documentation...

------
azakai
> Unlike JavaScript which can take hours to debug, haXe has a very strict
> compile-time type checking feature that allows you to catch errors before
> testing your program in the browser

It's great that you invented a new programming language. haXe is very cool.
But why do you feel the need to disparage other programming languages?

If you personally don't like dynamic typing, that's fine. But putting that in
the blurb for haXe will annoy a large potential audience for your language.
For what?

~~~
FlemishBeeCycle
While I disproportionally use Ruby and JavaScript on a daily basis, this
statement is referring to a specific type of (common) error, which is largely
alleviated by the use of static typing, and therefore not exactly untrue.

I didn't take it as a disparaging of dynamic typing.

~~~
azakai
It's not untrue.

But why the singling out of JavaScript? The statement is true for Python, Ruby
and Lua as well.

And why even mention another language or class of language in a negative way?
I propose that the sentence would better have been written as

> haXe has a very strict compile-time type checking feature that allows you to
> catch errors before testing your program in the browser

It loses nothing by removing the disparaging part.

~~~
FlemishBeeCycle
My guess is that rather than give an exhaustive list, the author wanted to
give an example of a familiar language _without_ static typing. As Haxe is
more similar to ECMAScript than Python, Ruby, Lua etc. - it's the most
appropriate comparison.

As a person who likes (the good parts of) JavaScript, I read it as trying to
appeal to me with promises of less debug time.

