The day has finally come. Haxe 4.2 has finally been released into the wild. I’m happy that with the new update a lot of features, improvements, and bug fixes have been added to the language. For a list of changes, you can find them all here. With that in mind, personally, one of the features stands out more than the others; that feature is module-level fields.

Module Level Fields

Module-level fields are a new feature to Haxe. You can find a detailed blog post on them here. The new feature essentially allows you to write your code in a more functional style and I’m all for it! Here’s an example to showcase the differences here. What it does is allow you to create functions and other parameters that you would have written inside of a class as part of the module. It’s like creating a new class with only static functions attached to it in Haxe before 4.2.0.

Here’s an example of the old way vs the new way.

//Example of a main entry point in Haxe before 4.2
class Main {
public static function main() {
trace('Hello World');
view raw Main-Old.hx hosted with ❤ by GitHub
Old Way
//Module Level Main entry point in Haxe 4.2.0
function main() {
trace('Hello World');
view raw Main-New.hx hosted with ❤ by GitHub
New Way

Can you see the difference? That’s a lot less typing and definitely a different programming style. As a result of this change, we can create Utility modules without creating a new class. Additionally, this opens up more coding styles for people to use in their programs and project to try different ways to write code. I know Haxe has a lot of the functional DNA within the code base, so finally being able to take better advantage of it at a large scale is great.

Once again, there are more awesome changes that came out, so please check out the post linked above.

With that said, I hope you have a great day and keep creating!

%d bloggers like this: