Skip to content

The Haxe Programming Language

Last updated on 2012-12-11

Yesterday I stumbled upon a new programming language called Haxe. The most prominent feature this language has over many other languages is that it is multi-platform (I heard that before… wasn’t Java also multi-platform? and Isn’t JavaScript multi-platform, running on top of most browsers?). But here multi-platform means that the language is compiled to many other languages, such as Java, C#, JavaScript, Flash, PHP, etc. Interesting.

But why another language? what is soooo wrong with the languages we have? I have programmed years with Java and while there are things that are harder to do in Java than in C#/Ruby/Haxe, I don’t think there are things that you can’t do. You may not be able to program like in JavaScript to use the browser as your new GUI, but you can write very nice user interfaces with Java nowadays. The goal is to write a GUI that the user can use, and that the programmer can maintain. NOT to write a JavaScript GUI. JavaScript is just a tool, like every other tool in the programmer’s toolbox.

I started reading the syntax of the language… Starts looking like Java but then strange things start to creep up. For example (taken from here), “Local functions are declared using the function keyword, but they can’t have a name. They’re values just like literal integers or strings” – so a function is a first class entity. But…”local functions declared in methods cannot access the this value. To access “this”, you need to declare a local variable such as me”:

class C {
  var x : Int;
  function f() { // WILL NOT COMPILE
    var add = function(n) { this.x += n; };
  function f2() { // will compile
    var me = this;
    var add = function(n) { me.x += n; };

But… why? one extra line of “noise” code who’s only reason is to let a local function have a handle to the instance that defines it. UGLY. Going through the next pages we see that “Declaring the type of a parameter in a class method or local function is also optional. The first time the function is used, the type of the parameter will be set to the type of the argument it was used with, just like local variables. This can be tricky since it will depend on the order in which the program is executed”. So you know this is tricky. Then why allow it?

Please, don’t think that I don’t value the work that the guys developing Haxe have done. Their work is a step in the correct direction – simplifying software development. But this road sometimes goes one step forward, one to the side, sometimes diagonally and even backwards (JavaScript). As a passionate programmer, I envy what these guys are doing. But at the same time as a Software Craftsman, I see another tool being added to the never-ending toolbox that we all carry around.

Enhanced by Zemanta
Published inProgramming

One Comment

  1. will will

    Yes, I agree with the syntactic difficulties. All languages have warts, that’s one reason I like to encourage people to be explicit when coding around default (warts) behaviour.

    I worked on a few languages that generated to C, Pascal and one for COBOL quite a few to FORTRAN. Generally those were domain specific languages (DSL). Why make a language that “looks like” C / Javascript / etc. that outputs something different? It would make more sense to augment one ‘target language’ they way C++ was an augmentation for C.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.