HaXe

From FlashSec

Jump to: navigation, search
haXe
Developer Nicolas Cannasse
Release 2.0
OS Windows, MacOS, Linux, BSD
Genre Compiler
License Unknown
Type Freeware
Website haXe Homepage
Documentation haXe Documentation
Wikipedia HaXe
OSFlash

haXe is a general-purpose, high-level, reflective, object oriented programming language developed by Nicolas Cannasse. It is possible to write both client and server layers of program in haXe, compiling client layer as Flash or JavaScript and server layer as Neko bytecode or PHP.

Contents

[edit] Main Features

  • haXe is statically typed, enabling the compiler to detect most errors at compile-time.
  • Uses type inference, allowing explicit type declarations to be omitted in most cases.
  • The standard library includes components designed to behave the same across all platforms.
  • Supports conditional compilation, so it is possible to have different implementations of an API depending on the target platform.
  • Syntax is similar to Java and ECMAScript, so it should be very familiar to JavaScript/ActionScript programmers.
  • Generics
  • Algebraic data types
  • Can be run in Apache by using mod_neko. mod_neko is available on Windows, Linux, Mac OS X and BSD systems.
  • Can compile a haXe program to .php files
  • haXe scripts can compile into a .swf file for the Adobe Flash Player, versions 6 through 9.
  • haXe has automatic delegate creation, which was a large problem for new developers using Actionscript 1 and 2.
  • haXe comes with all of the DHTML APIs that are needed, with some additional classes that reduce the number of cross-browser incompatibilities
  • haXe has a full-featured type system, so it is not necessary to test every bit of JavaScript to check if the program is correct or not, saving hours of Console Debugging.
  • Simply run the haXe compiler and it will output a single .js file to include in a website.


[edit] Code Examples

'Hello world!' textbox using ActionScript 2 (Flash 7 - 8) API:

class HelloWorld {
   static var start = flash.Lib.current.createTextField ('', 0, 0, 0, 200, 50).text = 'Hello world!';
}
  • haXe provides a syntax for defining local variables within expressions - block expressions { } which return the last expression within them.
  • An empty block expression is of type 'Void'.

import flash.display.TextField;
// AS3 API.
class HelloWorld2 {
   static var start = {
      var p = new TextField ();
      p.text = 'Hello world (two)!';
      flash.Lib.current.addChild (p);
      {};
   };
}
  • An example of type inference - argument/value types are determined automatically.
  • Functions can be passed as arguments to other functions where their type is determined by their argument and return types.
  • An anonymous function definition is an expression which returns a pointer to that function.

class Functions {
   static var start = {
      type (function (string : String, index, offset) {
         return string.charCodeAt (index) + offset;
      }); // string : String -> index : Int -> offset : Int -> Int
      type (function (func, param: String) : Float {
         return func (param);
      }); // func : (String -> Float) -> param : String -> Float
   };
}

[edit] Similar languages

Other programming languages operate in the same domain as haXe. Only a few, like Links and Hop, cover both the server and client side with the same language and API like haXe - avoiding most of the impedance mismatch problem. For the client side, alternatives include JavaScript interpreted directly by the browser, and ActionScript, OpenLaszlo and Neoswiff which all target the Flash platform. On the server side, typical Server-side scripting languages can be considered, as well as J2EE, Ruby on Rails, and more.

[edit] External links

[edit] General information about haXe

[edit] Development tools

[edit] Related technologies