The Haxe programming language is simple, fast and multi-platform. The same piece of object oriented code may be compiled into C++, Javascript or PHP.
In the past the question "which language do you program in?" had a simple answer: C; C++; Visual Basic. However, today the answer is slightly more complicated. Today the answer would be "it depends on the project that I'm working on today" or even "what time is it?". Gone are the days when a programmer could specialize in a single programming language and for them to expect to only know that.
Take, for example, a simple web application. A simple web application will require the use of at least Javascript on the client machine. If any server functionality is required (for example setting up an AJAX application that uses a MySQL database) then a knowledge of PHP is required as well (so that's two programming languages). And, of course, no web application is worth its salt if it can't be turned into an iPhone app. So, even for a simple application, at least 3 programming languages are needed (or maybe 3 programmers). And, of course, someone will want some Flash adding.
The answer to all of this is not to hire half a dozen programmers – it is to learn a new programming language, Just one – Haxe.
Haxe (which is pronounced 'hex') is free, open source and (most importantly) multi-platform. This means that it is possible for a programmer to write using a single, standardized language that currently targets:
C++
Flash
Javascript
Neko Virtual Machine
PHP
And work is currently under way to support:
C#
Java
The question is, therefore, can a single code file be written that may be compiled into any of the languages. The simple answer is – yes.
Creating a Multi-platform Program with Haxe
The starting point for any Haxe application is a simple text file. In this case the application with output the words "Hello World":
class Hello {
static function main() {
trace("Hello World !");
}
}
It is immediately obvious from this code that Haxe is an object-oriented language and that the file (which should be saved as "Hello.hx") contains the definition for a class. The class itself must contain at least one function – the obligatory "main".
That code can now be compiled into the target language by creating a file containing the compilation instructions. This file requires a .hxml suffix (for example php_compile.hxml) and contains the instructions detailing:
- the compilation language and output destination
- the class to be compiled
So, to compile the PHP "Hello" class into a directory named www the file contents would read:
-php www
-main Hello
Compilation is then a matter of double clicking on the .hxml file. The end result would be a PHP file that would load and run an instance of the class.
The format for a C++ compilation is similar to PHP:
-cpp cpp
-main Hello
And the end result would be a C++ executable.
Finally a Javascript file can be created from the code:
-js test.js
-main Test
Once great advantage at this point is that the compilation process identifies any problems with the code without the Javascript and PHP files needing to be loaded into a web browser. The application developer can now concentrate on the design rather than the semantics. And they can now do it more quickly and more efficiently.
Posted on Utopian.io - Rewarding Open Source Contributors
Thank you for the contribution. It has been approved.
You can contact us on Discord.
[utopian-moderator]
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Hey @haig I am @utopian-io. I have just upvoted you!
Achievements
Suggestions
Get Noticed!
Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!
Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit