Premiere C# support with Haxe

So C# is a language that’s very similar to haxe, modern, strongly typed, generics, LINQ, etc. But what Visual Studio brings to the table really changes the platform and the language:

  1. Code completion / intellisense for third party libraries
  2. Real time compilation and error detection (errors show up as you type)
  3. Multi-project solutions for large projects
  4. Project templates
  5. Extensions that install more templates and framework-specific tools
  6. Excellent memory and CPU profiling tools

Now if I go with VS Code instead, I’ll be missing out on many of these points. Thus, to fully take advantage of the C# platform, you need to use VS.

So now coming back to haxe, say I wanted to use haxe with C#, would I get:

  1. Code completion / intellisense for third party C# libraries
    Is there a way to specify third party C# library API so that haxe can read that metadata and show intellisense?
  2. Multi-project solutions for large projects
    Possible?
  3. Project templates
    Can haxe use an existing project for C# targets or does it generate its own?
  4. Extensions that install more templates and framework-specific tools
    Nevermind
  5. Excellent memory and CPU profiling tools
    We can use the same tools post-build, eg ANTS or Prefix

Yes, use --net-lib path/to/some-csharp-lib.dll. See .NET version and external libraries - Haxe - The Cross-platform Toolkit.

It depends on whether you want to let the Haxe compiler (actually hxcs) to compile the C# output, or you some other IDE/tools, which I guess you want to use Visual Studio as you described.

For the former, use multiple hxml files. By default, the Haxe compiler will call hxcs, which will in turn try to search for a C#/Mono compiler and call it to compile the C# output.

For the latter, use -D no-compilation to avoid the Haxe compiler compiling the C# output, and then you can create your own C# IDE project manually with reference to the C# output.

1 Like

Honestly, I don’t think hxcs is a good choice, why not use c# directly?

Well haxe allows me to reuse code across platforms, while C# does not. Is there an issue with hxcs that I should be aware of?

That’s great andy. I had no idea you could cancel compilation and use the regular build toolchain.

Hey robin7 :slight_smile:. Keep in mind that there are other IDEs out there. I currently use IntelliJ with Haxe Toolkit support and I’m quite happy with how things are going. I also have multiple projects and am quite fond of powerfull, full-fledged IDEs.

However, VS Code is growing very fast. It actually has some of the things you want, albeit perhaps not in such a finished form as the full-fledged VS. Did you give it a try? I know some dev rock stars who are all using VS Code, two of which I personally know and consider very mature professionals.

I think the extension ecosystem behind VS Code is possibly just as rich as VS. Regarding multi-project solutions for large projects, are you sure you already need that? You know, large projects aren’t what they used to be :wink: . Small and API-driven has been increasingly successful for a very good reason. I tend to prefer multiple IDE windows, where projects are compiled independently thus reducing compile time and forcing me to have an API-driven micro-architecture.

Speaking of compile time, did you know Haxe has a compilation server that can partially-compile code?

VS Code has been advancing at what I would call a very fast pace, also due to the huge community behind it. Keep in mind that it’s OSS and people will gradually add to it. It has taken more than 2 decades for VS to get where it is today, now imagine that VS Code is roughly 3 years old.

You seem to be in the early stages of a project, am I correct? In this situation, one of Haxe’s greatest powers lies in allowing you to ship an early prototype to more platforms and get exposure. I’m in the early stages of a production as well. For me, the greatest value is in focusing ON THE WORK, rather than what IDE or language this thing I’m building will be related to in the end.

Language/IDE are less relevant than getting some early feelings from a prototype. Haxe will get you there pretty fast if you know how to focus on its strengths. Care less about the stuff that is not yet perfect. If your projects rocks, you can build into Haxe whatever you want :slight_smile:. Just consider that people wrote new targets for Haxe just because they love what this language can do so much :slight_smile:. And if you at one point think that C# is better, just do a one-time conversion to C# at that point and that’s it.

I’ve looked at how Haxe transpiles to C# and it’s fairly clean. There are some things that are done a bit “low level” (such as generic constraints not using “where”, which C# does support) but we ARE talking about a one-time conversion. If anything, such an exercise will simply increase your knowledge of your own project and also, you will probably do it at a point when the project is quite far from release anyway.

That being said, I have “sampled” the Haxe ecosystem and even though it’s far behind some other languages, I have a gut feeling that this baby will skyrocket eventually. There are some really good engineers involved in this and, perhaps more importantly, the culture is good.

5 Likes

I saw you “writing…” for so long I was wondering what was cooking! That’s a really awesome answer and I think you understood my core concern here, which was “is haxe/hxcs mature enough for a real world project or should I go with C# instead”. And yes I’m in the early planning stages for a project. Of course I’m a big fan of the haxe language/compiler, especially the way you can target multiple platforms from a single codebase without the whole “write once, port many times” mantra that quickly becomes a reality with large and complex projects.

And yes, I personally use VS Code for a lot of projects, but I struggled to build even a basic VS Code + .NET Core application when I was evaluating it a month ago. I eventually gave up on trying to use C# with VS Code.

As of now I’d like to define the “premiere path” for each platform that haxe supports. Currently it supports so many platforms, but due to the complex and ever changing haxe technology its not really clear how to use which tool, or which toolchains to use for each supported platform.

I think we really need to improve documentation here. Perhaps some “recommended stacks” on the homepage that lets you know which platforms are supported and which tools you need to use which each.

1 Like

I completely agree with you that we could have some better documentation so that we can onboard developers coming with different needs! You might have seeded a good idea here :slight_smile:.

Haxe is like a swiss knife and the world is full of problems that a swiss knife can handle, but a mapping of /what tool/ and /how to use it/ versus /what real world problem/ could be very handy!

Perhaps this could be something that is part of the Haxe Code Cookbook ( https://code.haxe.org/ ) , an area of the Haxe ecosystem where I feel I can contribute.

For example, I’m trying to get Haxe off the ground with some unit testing tools. Couldn’t get munit off the ground yet, but I managed to do it with buddy. I’m thinking to contribute an article regarding this path. I’m also experimenting with two targets at once (Flash, because it was easy to get my prototype going there and JS, my long-term goal).

Later edit: and regarding what I said about VS Code, it just happens that in the space of a couple of hours @ablum came out to announce this:

2 Likes

Regarding the haxe completion server, unfortunately, there are issues specific to C# and Java targets that can be a problem on large codebases (see: setModuleCheckPolicy() breaks haxe server cache when targeting C# or Java · Issue #7652 · HaxeFoundation/haxe · GitHub).

I do hope this will be fixed sooner than later though.

I’ve created a new kind of page under /documentation/platforms/csharp.html. My goal is to create one page per platform, with detailed steps on getting started with all the tooling required for that platform. My PR is here.

Some screenshots:


4 Likes

This looks awesome. Nicely done, Robin!

3 Likes

IMHO there should be a few Docker images prepared for real world problems / use cases. You could have all these tools and dependencies running in a container(-s) and use it with your IDE.
I really like API Platform for such solution - it takes all the complexity off my system (and produces deployable containers) - premier support for me.

2 Likes

Current version of the guide : Haxe - The Cross-platform Toolkit