HaXe
Encyclopedia
haXe is a versatile open-source high-level multiplatform programming language
Programming language
A programming language is an artificial language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs that control the behavior of a machine and/or to express algorithms precisely....

 described on its website as a "universal language".

It can produce:
  • Flash applications and games
  • Multi-platform client-side web applications
  • Apache CGI web applications
  • Multi-platform stand-alone applications (Windows, Linux, Mac OS), including mobile applications for platforms such as webOS or the iPhone. The latter generally requires additional SDKs to utilize the platform.


The code can be produced entirely within the haXe development environment, sometimes requiring Neko
Neko (programming language)
Neko is a high-level dynamically typed programming language developed by Nicolas Cannasse as part of R&D efforts at Motion-Twin.-Concept:Neko has a compiler and a virtual machine with garbage collection. The compiler converts a source .neko file into a bytecode .n file that can be executed with the...

, by using a single and unmodified code-base when compiling from one target to the next.

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 2.08, which was released on 28 September 2011.

According to MTASC.org http://www.mtasc.org HaXe is the "successor" to MTASC
MTASC
MTASC is an ActionScript 2.0 compiler written in the Objective Caml programming language by the company Motion-Twin. It is free software and can be used alone or with other tools like swfmill to produce SWF files, which contain interactive multimedia content playable with the Flash Player...

 (the MTASC website has advertised on its homepage "MTASC successor's haXe ! See haXe.org website", and MTASC development ceased as soon as HaXe went public, and both compilers were created by Nicolas Cannasse). HaXe code therefore has much in common with AS3 but with many improvements and output capabilities which puts it in an entirely different category than the Adobe Compilers.

Originally its main advantage was the combination of wide platform-independence and a fully developed high-level language. An increasingly noteworthy advantage is its ability to use such a language to target a device-manufacturer who allows only C++ based code, their own IDE, and very little else.

The haXe compiler is released under the GNU General Public License version 2
GNU General Public License
The GNU General Public License is the most widely used free software license, originally written by Richard Stallman for the GNU Project....

.

Naming and pronunciation

The name haXe was chosen because it is short, simple, and "has an X inside", which the author asserts, with apparent humor, is necessary to make any new technology a success.

Output targets

The haXe technology derives its "universal language" moniker because of its ability to target different virtual machines supported on a plethora of OS's and devices, as well as the ability to translate the code from a haXe program into different source-code languages. This strategy of "compiling" to multiple source code languages greatly extends its ability to realize the write-once, deploy-everywhere paradigm when compared to compilers that compile directly to different operating systems. It also allows the programmer to choose the best compiler when compiling an executable, use haXe as a high-level way to quickly create complex components for a lower-level language like C++, as well as further edit and utilize libraries from another IDE.

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.

Current targets:
  • Flash
    Adobe Flash Player
    The Adobe Flash Player is software for viewing multimedia, Rich Internet Applications and streaming video and audio, on a computer web browser or on supported mobile devices. Flash Player runs SWF files that can be created by the Adobe Flash authoring tool, by Adobe Flex or by a number of other...

     6-8 (AVM1)
  • Flash
    Adobe Flash Player
    The Adobe Flash Player is software for viewing multimedia, Rich Internet Applications and streaming video and audio, on a computer web browser or on supported mobile devices. Flash Player runs SWF files that can be created by the Adobe Flash authoring tool, by Adobe Flex or by a number of other...

     9-11 (AVM2)
  • Neko
    Neko (programming language)
    Neko is a high-level dynamically typed programming language developed by Nicolas Cannasse as part of R&D efforts at Motion-Twin.-Concept:Neko has a compiler and a virtual machine with garbage collection. The compiler converts a source .neko file into a bytecode .n file that can be executed with the...

  • PHP
    PHP
    PHP is a general-purpose server-side scripting language originally designed for web development to produce dynamic web pages. For this purpose, PHP code is embedded into the HTML source document and interpreted by a web server with a PHP processor module, which generates the web page document...

  • AS3 (outputs AS source code)
  • JavaScript
    JavaScript
    JavaScript is a prototype-based scripting language that is dynamic, weakly typed and has first-class functions. It is a multi-paradigm language, supporting object-oriented, imperative, and functional programming styles....

  • C++
    C++
    C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as an intermediate-level language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell...



Targets in development:
  • Java
    Java (programming language)
    Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...

  • C#


Using these targets, one can do all the coding for any of the following entirely from within the haXe/Neko development environment requiring little if any modifications going from one target to the next:
  1. a client-side web application (by outputting to Flash, or Javascript
    JavaScript
    JavaScript is a prototype-based scripting language that is dynamic, weakly typed and has first-class functions. It is a multi-paradigm language, supporting object-oriented, imperative, and functional programming styles....

     targets),
  2. a server-side web application (by outputting to PHP
    PHP
    PHP is a general-purpose server-side scripting language originally designed for web development to produce dynamic web pages. For this purpose, PHP code is embedded into the HTML source document and interpreted by a web server with a PHP processor module, which generates the web page document...

    , or Neko
    Neko (programming language)
    Neko is a high-level dynamically typed programming language developed by Nicolas Cannasse as part of R&D efforts at Motion-Twin.-Concept:Neko has a compiler and a virtual machine with garbage collection. The compiler converts a source .neko file into a bytecode .n file that can be executed with the...

     targets),
  3. a stand-alone application for Windows, Linux, or Mac OS (by outputting to C++
    C++
    C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as an intermediate-level language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell...

    , or Neko
    Neko (programming language)
    Neko is a high-level dynamically typed programming language developed by Nicolas Cannasse as part of R&D efforts at Motion-Twin.-Concept:Neko has a compiler and a virtual machine with garbage collection. The compiler converts a source .neko file into a bytecode .n file that can be executed with the...

     targets), and even ...
  4. a native-code application for mobile OS platforms like iOS, Android or webOS by targeting output to C++ - although this last option generally requires additional SDK's to utilize the platform.

Language

Since haXe had its origins in AS3, all of the existing Flash API can be used, although haXe requires better-formed code and programming standards than do Adobe compilers (for example, with regard to scoping
Scope (programming)
In computer programming, scope is an enclosing context where values and expressions are associated. Various programming languages have various types of scopes. The type of scope determines what kind of entities it can contain and how it affects them—or semantics...

 and data typing
Data type
In computer programming, a data type is a classification identifying one of various types of data, such as floating-point, integer, or Boolean, that determines the possible values for that type; the operations that can be done on values of that type; the meaning of the data; and the way values of...

).

HaXe is, like AS3.0, similar to ECMAScript
ECMAScript
ECMAScript is the scripting language standardized by Ecma International in the ECMA-262 specification and ISO/IEC 16262. The language is widely used for client-side scripting on the web, in the form of several well-known dialects such as JavaScript, JScript, and ActionScript.- History :JavaScript...

, although almost no ECMAScript code will run on haXe without modifications. Unlike ECMAScript, haXe is a compiled language
Compiled language
A compiled language is a programming language whose implementations are typically compilers , and not interpreters ....

. It is a general-purpose language with object-oriented programming, exceptions, and type inference with class parameters. Generic classes
Generic programming
In a broad definition, generic programming is a style of computer programming in which algorithms are written in terms of to-be-specified-later types that are then instantiated when needed for specific types provided as parameters...

, reflectivity
Reflection (computer science)
In computer science, reflection is the process by which a computer program can observe and modify its own structure and behavior at runtime....

, iterator
Iterator
In computer programming, an iterator is an object that enables a programmer to traverse a container. Various types of iterators are often provided via a container's interface...

s, and functional programming
Functional programming
In computer science, functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids state and mutable data. It emphasizes the application of functions, in contrast to the imperative programming style, which emphasizes changes in state...

 are built-in functionality of the language and libraries. Unusual among programming languages, haXe contains a type system which is both strong and dynamic. The compiler will check types implicitly
Type inference
Type inference refers to the automatic deduction of the type of an expression in a programming language. If some, but not all, type annotations are already present it is referred to as type reconstruction....

 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>>, stringval : String, boolval : Bool) {
}
// optional int value returning an int
function optionalargument ( ?i : Int ) : Int {
return 0;
}
// call a function with no parameters
function functionasparameter ( f : Void -> Void ) {
f;
}
// call a function that returns an int, with an int parameter
function anotherfunctionparm ( f : Int -> Int ) {
var result = f(1);
}
// function which takes any kind of type and returns it
function icoulddoanything (d : Dynamic) : Dynamic {
return d;
}


Enumerated type
Enumerated type
In computer programming, an enumerated type is a data type consisting of a set of named values called elements, members or enumerators of the type. The enumerator names are usually identifiers that behave as constants in the language...

s are a key feature of the language; they can have parameters of their own and be recursive. They are similar to algebraic data types in languages like ML or Haskell
Haskell (programming language)
Haskell is a standardized, general-purpose purely functional programming language, with non-strict semantics and strong static typing. It is named after logician Haskell Curry. In Haskell, "a function is a first-class citizen" of the programming language. As a functional programming language, the...

. 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: 0xFF0000;
case green: 0x00FF00;
case blue: 0x0000FF;
case rgb(r, g, b): (r << 16) | (g << 8) | b;
}
}
static function validCalls {
var redint = toInt(Color.red);
var rgbint = toInt(Color.rgb(100,100,100));
}
} (Modified from the haXe Reference)

Demonstrating haXe for graphical uses, here is some example code for the Adobe Flash (AS2, i.e. AVM1) target (from the haXe website):


class Test {
static function main {
var mc: flash.display.MovieClip = flash.Lib.current;
mc.graphics.beginFill(0xFF0000);
mc.graphics.moveTo(50,50);
mc.graphics.lineTo(100,50);
mc.graphics.lineTo(100,100);
mc.graphics.lineTo(50,100);
mc.graphics.endFill;
}
}


This will draw a square using a Flash MovieClip object.

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 indicates that haXe compiles Flash 9 (AVM2) bytecode with better performance than the equivalent AS3 code on Adobe's compiler. Since publication of this benchmark the compiler has further improved performance features with the addition of inline function
Inline function
In various versions of the C and C++ programming languages, an inline function is a function upon which the compiler has been requested to perform inline expansion...

s and hidden Alchemy
Alchemy (Adobe)
Alchemy is a research project from Adobe Systems that allows compiling C and C++ code to ActionScript Virtual Machine , so that it can be run on Flash Player or Adobe AIR. This is achieved by compiling C/C++ code to LLVM bytecode and then translating LLVM to ActionScript 3 with inlined AVM2...

 opcodes that Flash does not use.

See also

  • Dart
    Dart (programming language)
    Dart is a Web programming language developed by Google. It was unveiled at the in Aarhus, 2011 October 10-12. The goal of Dart is "ultimately to replace JavaScript as the lingua franca of web development on the open web platform."- Reason for a new language :Dart is intended to solve JavaScript's...

     - similar programming language for web apps
  • Opa
    Opa (programming language)
    Opa is an open source programming language for web applications.The language was first officially presented at the OWASP conference in 2010, and the source code was released onGitHubin June 2011, under a GNU Affero General Public License....

    - another similar programming language for web apps

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK