haXe
From Wikipedia, the free encyclopedia
haXe is a programming language, designed for creating interactive web applications. Currently there are three official compiler targets - Adobe Flash, JavaScript and the Neko VM.[1]
Contents |
[edit] History
Development of haXe was started on the 22nd of October, 2005. The first alpha version of haXe was released on the 14th of November, in the same year. The first beta version was released on the 4th of February, 2006. haXe 1.0 was released on the 17th of April, in the same year. The current release of haXe is version 1.19, which was released on the 5th of April, 2008.[2]
haXe is released under the GNU General Public License.[3]
[edit] Naming and pronunciation
The name haXe was chosen because it is short, easy, cool, and "has an X inside", which the author claims is necessary to make any new technology a success.[4]
There is currently no official pronunciation of haXe. However, common pronunciations are "hex" (due to the fact that the author is French), "hacks", "aytch axe".[5]
[edit] Language
The header of the official haXe site describes haXe as a "web oriented universal language." The feature that is tied to this description is the compiler's ability to target different virtual machines: Adobe Flash's AVM1(Flash 6-8) and AVM2(Flash 9+), Javascript, and NekoVM, the last being a general-purpose virtual machine also built by haXe creator Nicolas Cannasse. The haXe language and libraries are designed to achieve maximal support of these target platforms, and the compiler will emit target source or bytecode depending on the language and options selected. The "web oriented universal" moniker follows from this ability to deploy the same code across different layers of a WWW application. The haXe community has shown interest in adding PHP[6] and Java[7] support.
haXe is similar to ECMAScript, although almost no ECMAScript code will run on haXe without modifications. Unlike ECMAScript, haXe is a compiled language. It is a general-purpose language with object-oriented programming, exceptions, and type inference with class parameters. Generic classes, reflectivity, iterators, and functional programming are built-in functionality of the language and libraries.[8] Unusually among programming languages, haXe contains a type system which is both strong and dynamic. The compiler will check types implicitly and give compile-time errors, but it also enables the programmer to bypass type-checking and rely on the target platform's dynamic type-handling.
Function parameters can be defined very precisely in haXe:
function multipleparams(threedimensionalarray : Array<Array<Array<Int>>>, stringval : String, boolval : Bool) {} function optionalargument( ?i : Int ) : Int {return 0;} // optional int value returning an int function functionasparameter( f : Void -> Void ) {f();} // call a function with no parameters function anotherfunctionparm( f : Int -> Int ) {var result = f(1);} // call a function that returns an int, with an int parameter function icoulddoanything(d : Dynamic) : Dynamic {return d;} // function which takes any kind of type and returns it
Enumerated types are a key feature of the language, they can have parameters of their own and be recursive, which allows them to be treated like classes.[9] Enums in haXe are not simply indexed "magic-number" values as in most languages, but are more abstract: they contain no inherent value, but can be instanced into variables as in this example:
enum Color { red; green; blue; rgb: ( r : Int, g : Int, b : Int ); } class Colors { static function toInt( c : Color ) : Int { return switch( c ) { case red: 0xFF000; case green: 0x00FF00; case blue: 0x0000FF; case rgb(r,g,b): (r << 16) | (g << 8) | b; } } static function validCalls() { var redint = toInt(red); var rgbint = toInt(rgb(100,100,100)); } }
(Modified from the haXe Reference)
Demonstrating haXe for graphical uses, here is some example code for the Adobe Flash target (from the haXe website):
class Test { static function main { var mc : flash.MovieClip = flash.Lib.current; mc.beginFill(0xFF0000); mc.moveTo(50,50); mc.lineTo(100,50); mc.lineTo(100,100); mc.lineTo(50,100); mc.endFill(); } }
This will draw a square using a Flash MovieClip object.
[edit] Compiler implementation and performance
The haXe compiler is implemented in the OCaml language. Because haXe-generated code runs on virtual machines, no knowledge of OCaml is necessary to develop applications using haXe. This also means that benchmark performance varies depending on the target platform, as each platform must be customized to make the best use of available features.
One benchmark[10] indicates that haXe compiles Flash 9(AVM2) bytecode with better performance than the equivalent AS3 code on Adobe's compiler. Since this benchmark the compiler has further improved performance features with the addition of inline functions.
[edit] References
- ^ haXe introduction page.
- ^ haXe 1.19 release.
- ^ haXe download page.
- ^ haXe mailing list post on naming.
- ^ haXe mailing list post on pronunciation.
- ^ PHP discussion thread.
- ^ Java discussion thread.
- ^ haXe language reference.
- ^ haXe reference detailing the use of enum.
- ^ AS3->haXe port of the Actionscript Physics Library.