Haxe is an open source programming language which targets several platforms.
Today, most of the available mainstream languages come with their own platform. For instance, the popular Java programming language can be run on the Java Virtual Machine (JVM) platform, PHP can be run using
As a developer, it is hard to develop expertise in all of the existing platforms : there are many of them, each coming with its own programming language, syntax and API, and each being updated on a regular basis with new features.
Using several platforms
Looking at it more positively, it's also a very good thing to be able to use several platforms, since it enables you to choose the best technology for every project, or to mix several platforms together to make something creative that would have not been possible with a single technology.
Of course, learning all these different technologies can be very time-consuming, since it requires you to learn a lot of different languages, often using different IDEs or tools, to master the APIs for each set of standard libraries, etc..
This where Haxe comes to help.
Instead of having its own platform, a Haxe program can be compiled by using the Haxe compiler into another program that will be able to run on the target platform.
For instance, a Haxe program can be compiled into a
Haxe has many standardized APIs which will run exactly the same on all platforms. This ensures that developers can master a platform independent language while targeting another supported platform.
These standardized APIs include support of Arrays, Lists, Dates, XML, regular expressions as well as sophisticated features like full runtime reflection, abstract I/O, serialization, unit testing and more.
Haxe also has platform-specific APIs that enable you to access the features that are specific to a given target platform. For instance, if you target the Flash platform, you will have access to all the sound, video and graphics API that are available in the Flash Player.
In general, all API libraries that a given platform offers are also accessible from Haxe. The goal of Haxe is to give the developers all the capabilities of a given platform. But keep in mind that since the Haxe application is running on a specific platform, it can't do more than the platform allows.
Haxe is not a framework : it's just a toolbox that you can use to target any supported platform. It does not impose any specific application-design rules, although you can use frameworks written in Haxe to develop your application.
In short, once you learn Haxe, the only remaining job you'll have to do when starting a new platform is to know how to use the platform-specific APIs. This will be much easier than switching platform technology and programing language at once.
Let's have a look at all the platforms that are currently supported by Haxe...
A Haxe program can be compiled to a single
.jsfiles, and if you use a JS library you often have to include the whole library while you only use some parts of it. Haxe only compiles the minimal set of classes that you are using into the final
.jsfile, making it as small as possible.
The Adobe Flash Player is installed on most Internet web browsers, and is also available on some mobile phones and devices.
Flash provides an effective, simple to use, high speed graphics technology that can be used to develop interactive graphical applications such as games and interactive web-sites. In addition, Flash also provides sound and video playback and recording (using microphone and webcam).
There are three languages and two virtual machines that are part of the Flash technology : the ActionScript 1 and ActionScript 2 languages run on the AVM and the ActionScript3 language runs on the latest AVM2 that was introduced with Flash Player version 9 in 2006 with a brand new API.
Haxe can target both of these virtual machines, which are considered two different platforms called
flash9. We recommend using the
flash9 platform if you just got started with Flash since it provides a more mature API and better execution speed.
A Haxe program for the Flash platform is compiled to a
.swf binary file which can be run by the Flash Player. This makes Haxe a good replacement for programming in ActionScript 1, AS2 and AS3.
Haxe is often considered a better programming language than the most recent AS3 because it provides features such as generics and type-inference. The compiler also runs faster and produces faster code than the AS3 compiler, which makes Haxe a good choice for professional users.
However, Haxe provides several tools to leverage your existing investment in software and to take advantage of third-party Flash and AS3 toolkits and libraries:
- Haxe can use a
.swflibrary produced by the Flash IDE that contains graphics assets
- Haxe can also output
SWCfiles, which enable libraries written in Haxe to be used from AS3.
- Haxe has an AS3 generator which will enable you automatically convert a Haxe program into the corresponding AS3 code.
Another reason that some people prefer to use Haxe is because of its open-source nature, which makes its evolution independent from marketing-driven decisions of Adobe.
PHP is a popular technology for developing dynamic websites that require server-side programs. It can access databases, filesystems and services available on the server. It typically runs under an Apache web server by using
However, in the past years, PHP has incrementally added features coming from more classical Object Oriented languages such as Java, and has became overly complicated because such features were not designed from the start into the language.
If you want to forget about the PHP language quirks, while still be able to run your websites through
mod_php, then Haxe might be a good solution for you. The Haxe compiler will compile the Haxe programs into corresponding PHP ones, and will provide you a complete static type system which will enable you to detect most syntax and typing errors at compile-time without the need to visit the website to check if something is wrong or not.
The Neko Virtual Machine is a lightweight and fast virtual machine that can be easily embedded into any application. The NekoVM runs neko bytecode stored in binary
.n files that can be generated by Haxe when targeting the Neko platform.
As part of the Neko libraries, the ''mod_neko" Apache module is provided. This makes it possible to develop the server-side part of a website with Haxe and it on Neko. Neko also provides full filesystem and database access.
The PHP-specific API that is provided with Haxe is also fully compatible with Neko, so you should be able to compile an existing Haxe/PHP website for Neko as well. The main advantage is that the Neko Virtual Machine runs about 30 times faster than the PHP one.
The VM can also be extended with additional libraries written in C, making it possible to access any native technology from Haxe, and to develop full desktop applications in Haxe, or to use Haxe as a scripting language for an application.
Finally, you can easily run a
.n file from the command-line or convert it into a binary executable, make also the platform a good choice to develop small command-line tools.
The C++ target is still experimental and should be available starting with Haxe 2.04
A Haxe program can be compiled into several
.cpp files that can then be compiled with any C++ compiler and enable you to write desktop applications using Haxe.
The Haxe C++ complier comes with APIs that are compatible with Neko ones, and also an external library which emulates the Flash API, making it possible to run many Haxe/Flash applications with native speed as well.
While the C++ target is still under development, it provides very good performance for all numerical-intensive applications, as well as direct accesses to 3D technologies such as OpenGL.
The target platforms will, without doubt, continue to evolve, and it's the job of Haxe to keep up-to-date with this evolution.
We can differentiate the kinds of improvements that a given platform can make as follows:
- language/syntax improvements : since Haxe has its own language and features, and its own independent evolution, Haxe will not have to keep up-to-date with these changes. In cases where these improvements can improve performance, Haxe will still be able to exploit these in a transparent manner.
- new apis/features : Haxe should provide access to the new API of a given platforms as soon as they are publicly available.
- speed/bugfixes : since Haxe runs on the same platform, it will directly benefit from speed improvements or bugfixes that are done.
In some cases, a platform can undergo major changes in its language and/or runtime. The Haxe language has been designed to be able to adapt these changes and the fact that it can already run on all these different platforms is already a proof of its capabilities.
Building cross-platform code
While it's not strictly needed, it can be convenient when you are using several platforms in different projects on a daily basis, to be able to develop code that will run the same on all platforms.
This is already what the Haxe standard library is doing, so as long as your program does only rely on the standard library, it will naturally be cross-platform.
However, if in some cases you want to be able to use platform-specific API, then Haxe has conditional compilation which makes it possible to write code that will compile differently, depending on the target platform.
HaXe is a good way to build your own cross-platform API that you can reuse in your different projects.