COMMUNITY

Haxe as one one language for websites

haxe-php
haxe-js

#1

Hello guys,

I am using the Haxe last year and I like it. I am freelancer who making games with the Haxe and websites based on classic technologies such as php and javascript. I am using haxe only on js right now but I wish to write my code in one language and really really serious start build big, huge framework for my company which can help people more easier build their websites, eshop etc.

On based on that I have more question:

  1. can I use haxe-php like a full compensation php? Or what points there are that cannot compensate
  2. can you recommend please any 3d engine code examples that are done?
  3. at the end is Haxe really good way to build any big project where are more technologies together, in my case php and js? any support documentation how build it together, clean…

Thank you lots of.


(Michael Solomon) #2

I just want to recommend you to not re-invent the wheel but use one of the already exists eco-system in haxe like tink, ufront or hexMachina.


#3

I agree. Thank you for your comment


(Alexander Blum) #4

Using existing frameworks might get you started quicker, because they already solve the basics. But you also have to adopt their way of thinking, their way of doing things, which might not be how you prefer to solve your problems or how you organise your logic / code.
So I’d say take a look at them and maybe try them out, but if you find that they don’t work for you, then you can as well just get your hands dirty and write your own framework.

I use Haxe to build PHP and JS sites and I decided to write my own framework (a couple years back) - it’s a lot of work, but you can start small and expand with every project, adding more and more features. Thanks to Haxe I am able to use my framework or parts of it even in C++ or Java projects, which I didn’t plan for when I started, my focus was on PHP and JS.
It has about 40K lines of code as of now, just to give you a number… I guess someday I need to split it up into smaller parts.
Features include a database layer, a logging mechanism, a mail implementation, easy to use form fields, and a bunch more.

So it’s possible to do it, and it might be the right way to go for you. If you already have your own framework written in PHP, then porting it over to Haxe should be pretty straight forward - if you have the time to do it. That way you can continue to work as you did in pure PHP, but you get type safety and all the other Haxe goodness.

As to reinventing the wheel: Sometimes it’s fun to be able to reinvent the wheel. And it’s not like there are hundreds of wheels to choose from, especially for web development.
There is also a section about wheels in The Joy of Haxe

Just in case someone asks: Unfortunately there are currently no plans to release my framework as open source.


#5

Thanks for your comment


(Allan Dowdeswell) #6

I also am a freelancer who has similar needs / wants / use cases. To answer your points:

  1. @Michael makes a good point. I’ve built my own site using UFront, which I love, but it is not PHP7 compatible yet and it seems to have fallen out of favour in the Haxe community a bit due to its age (I care less about that). Great thing about Ufront is that it will operate without Javascript if necessary. Tink and hexmachina are strong and more popular. It’s also possible to make a Joomla! component using Haxe. This works but I believe it would have been more successful had I built some clever macros to make integration easier—could have avoided so many --next directives in the hxml file. Likely not what you’re looking for. Check out Sugoi and Tamina also.
  2. There’s MinkoHx, Away3D, ThreeHX, BabylonHx, Sandy (old), Heaps, Armory, plus externs for Three.js, Unreal, Unity.
  3. Haxe documents are best start. Tink documents are well done.

(Дмитрий Маликов) #7

haxe php generator was rewriten
so i turned back to haxe from php

i think - Haxe as static typed language - is good replacement for PHP
even without any frameworks

frameworks not big deal today - when you use some rest api
get parameters - output json - that’s it

Haxe php lib is good - in many cases you can write code only on Haxe, without writing native PHP code

but you have to make some externs for existing PHP libs


(Marcelo Serpa) #8

Your best bet would be to leverage already-existing frameworks in one of the targets. Pick one and stick to it. I recommend just going with JS. The cross-platform aspect of Haxe is not very useful here, I’d say. If it becomes hard to integrate, you may try to use a custom generator or search for a lib that already does the work for you (https://github.com/massiveinteractive/haxe-react, for example).

For server-side, it’s easy to just target ES5 and vanilla Haxe with Express.

Another alternative is to use a cutting-edge Haxe web framework. The only serious non-game libs being developed at the moment (that I know of) are the tink libs (hats off to @back2dos, @kevinresol and @benmerckx). There’s tink_web which has the advantage of being cross-platform (but nodejs is the best-supported target, AFAIK).

As a side note, the main challenge I haxe with Haxe for web/mobile at the moment is integration with Typescript. If I want to say, use Haxe instead of Typescript for Ionic it’s a huge pain in the ***. It would be possible with a custom generator (hxgenjs), but I decided to just go wtih TS for now. One might say to just bypass the Ionic build tool and figure out the ES5 output, but that’s even more work. The point I want to make in this paragraph is that I’d love to use Haxe for everything js, but nowadays it’d require ways to more easily integrate Haxe code with TS (and ES6) code (maybe a TS target?).


#9

Thank you so much guys for you answers. I appreciate


(François Barbut) #10

Hi There.

I’m very glad to see more developers diving into haxe/PHP !
I think Haxe has the potential to become the “Typescript of PHP”.

Currently using haxe/Neko, I will soon migrate my open source app ( https://github.com/bablukid/cagette ) and my web framework ( http://sugoi.bubar.info ) to haxe/PHP7 ( and therefore give up Neko ).

I also plan to take advantage of the PHP ecosystem, and will start to make externs for reknown PHP libs like Twig or swiftMailer.

@ablum I would love to know more about your tools and sharing tips , is the code available somewhere ?

-François


(Alexander Blum) #11

@bubar right now there is no public code. I wouldn’t completely rule out an open source release some day, but there is no real plan.
As it is, it works for me, but I guess a release should be partitioned into smaller bits. I already split off half a CMS into a separate library, but most stuff is intertwined, so it’s not an easy job where cutting off at package boundries would work.
Also there are lots of areas that are only half done or only work for what I need them to…

When you are going for PHP7, it should be fairly straight forward, most stuff should run with -D php7, but you might want to look at changes that come with Haxe 4, especially php.Syntax, because untyped __php__, etc. are on their way out…


(Kevin Leung) #12

I have shipped a few web apps, mobile apps (together with their app servers) and mini games with Haxe already. I mainly use the JS target.

  • web app = js (browser)
  • mobile app = js (react-native)
  • app server = js (nodejs)
  • mini games = js (browser/electron) / cpp

The main Haxe libraries I use are tink_web, coconut.vdom / coconut.react, openfl. I also utilize a lot of js libraries from npm.


(Marcelo Serpa) #13

@kevinresol

Do you happen to use Typescript as well or libraries/frameworks that are written in TS and have to integrate with Haxe code? If so, do you mind sharing some of your integration experiences?

Lately, I have found it easier to have the “shell” (as in the entry-point and maybe some support code/classes) of the project in TS and use hxgenjs to implement the “core” in Haxe and then use from TS. This is especially useful if you want to use Haxe with frameworks that are very strongly TS-opinionated and have a dedicated build system like Ionic. You’d have a “shell” (or maybe we should say “header”) TS class that supports all the Ionic/Angular mixin tags, etc, and that the Ionic build system understands and can make sense of (it’s based on webpack, btw), and then you forward the needed reference or values to an inner Haxe class (generated from hxgenjs with a d.ts definition file).

For projects that only use external libraries written in TS (which end up being js anyway) this is less of a problem and Haxe externs can do the job, so you don’t need those TS “header” classes.

I’m sure someone with more time and smarter then me could create a generator to make it easier to generate code that’s compliant with frameworks like Ionic or EmberJS without having to fall back to ES5, which means you skip the build systems, which is undesirable. Also, many of these frameworks do not officially support ES5, so you have to reverse-engineer a lot of the higher-level code on your own, which means a lot of time wasted, and you can’t leverage the docs for that frameworks as they are. You basically end up marginalized user of that framework, from the start.

I think this subject would justify its own post but I thought we could trigger the discussion here and see if there’s interest in digging deeper into it.