22

Facebook have introduced a new programming language, which looks mostly like an extension to PHP. They've called it Hack and it's running on their HHVM engine.

After seeing their website and reading a bit about it, I wondered how fluid a migration from PHP to Hack could potentially be.

Let's base this discussion around a web application already deployed to a LEMP or LAMP stack.

Some of my initial thoughts and list of actions include:

  • How do I run both PHP and Hack in the process of migrating the code base?
  • Migrate from nginx/Apache to HHVM
  • Migrate code base iteratively

So, how would you approach this?

erginduran
  • 1,497
  • 4
  • 23
  • 47
Ronni Egeriis Persson
  • 2,069
  • 1
  • 19
  • 42
  • 2
    This might be better as several (interesting) questions rather than bundled in one. – Brian Warshaw Mar 20 '14 at 17:55
  • 2
    @BrianWarshaw not really. Even as individual questions, they are all either too broad or opinion based. – Mike Mar 20 '14 at 17:58
  • 1
    @Mike I'll call an audible and say that I said "better", not "perfect" :-) – Brian Warshaw Mar 20 '14 at 18:03
  • I just caught the press release myself and am doing the tutorials and documentation now. I'd assume, like Mike said, that the only answers for now are opinions. Until people start installing and developing on the language, we're all just reading the same documentation and press releases. – skrilled Mar 20 '14 at 18:05
  • Thanks to @PaulTarjan for adding the `hacklang` tag :-) – Ronni Egeriis Persson Mar 20 '14 at 22:32
  • Here is a guide that can help you get started: https://joltup.com/how-to-install-hacklang-on-ubuntu-apache-nginx/ – tslater Mar 23 '14 at 09:53

2 Answers2

31

I'm an engineer at Facebook who worked on Hack. In particular, I wrote several parts of the conversion tools and then applied them across Facebook's codebase. This indeed should probably be several questions -- it depends on how exactly your project is set up, what PHP feature you're using, and so forth. Some good starting resources include:

  • Get HHVM installed. Right now, Hack is only available if you use the nightly packages (only available for Debian and Ubuntu) or if you compile from our github source, so make sure you do one or the other.
  • Get your code running on HHVM with nginx and fastcgi. This should be pretty straightforward -- HHVM is supposed to run PHP code out of the box. If it doesn't, it's a bug.
  • Get the Hack typechecker running on your project. This won't do much since all your code is PHP.
  • Start running our conversion tools and getting more Hack code in your codebase. We seamlessly interoperate with PHP, so you can do as much or as little of this as you want, as quickly or as slowly as you want. From here, you're golden -- do whatever makes sense for your project!

That's what you need to get started. Specific followups would be best asked as a separate question. I'll try to keep an eye on SO and answer where I can to help folks get started! You can also join us on IRC, #hhvm on Freenode.

Josh Watzman
  • 6,460
  • 1
  • 16
  • 26
  • Thank you Josh, appreciate you taking the time to post these steps. This answers what I was thinking about when I heard about Hack. Good job with it! – Ronni Egeriis Persson Mar 20 '14 at 22:32
  • Is there (will there be) some formal specification for Hack ? a.k.a. all changes that it introduces compared to PHP. I took a look at your Tutorial, looks awesome, but I don't know how complete it is. Also, you said that you need a HHVM nightly build to run Hack; so does that mean that it will be available in HHVM 3.0 (to be launched next week) ? Either way, +1 for a great answer coming straight from the source :D – Radu Murzea Mar 21 '14 at 14:50
  • There's no formal specification for Hack right now (but there isn't one for PHP either). Hack will be included in HHVM 3.0 when it launches next week -- we just didn't think it was worth making an out-of-cycle release when the nightlies work well enough for people that want to give Hack a try. – Josh Watzman Mar 21 '14 at 20:55
  • @JoshWatzman, Is there a way to compile hack scripts to PHP code so that we don't need HHVM on our setup to run it? Is such a tool already currently in development? – Pacerier Feb 08 '15 at 14:21
  • @Pacerier you can try h2tp: http://docs.hhvm.com/manual/en/install.hack.h2tp.php -- it's still fairly experimental, and designed for a final deploy step as opposed to day-to-day development. I would in fact recommend against using it for day-to-day development -- you really need to be using HHVM plus the Hack typechecker to get the most out of Hack. – Josh Watzman Feb 09 '15 at 00:08
  • I came up with this simple utility which converts given php class to hack, http://php2hack.org I am using it for converting my small projects, will be adding directory support to it soon. – Aftab Naveed Feb 09 '15 at 05:18
  • @JoshWatzman, Would be great if we could have a standalone Hack-to-PHP tool that can be used as part of the development process. In many shops management wouldn't want to install HHVM and with that tool we can still use Hack despite that. – Pacerier Feb 09 '15 at 22:46
  • 2
    @JoshWatzman All these links are now broken. Would it be possible to update this answer for 2017 since it is the very first Google result when searching "migrate app from php to hack"? – DavidScherer Oct 25 '17 at 15:17
  • @DavidScherer, Facebook killed the transpiler: https://github.com/facebook/hhvm/issues/7424#issuecomment-346176489 – Pacerier Nov 21 '17 at 22:16
  • @JoshWatzman, Why did they decide to kill the transpiler? – Pacerier Nov 21 '17 at 22:17
1

From the sounds of it, it will be nearly seamless to transition. From the Wired Article about it:

Hack will be particularly attractive, Adermann says, to existing PHP shops. “Ironically,” he says, “its chief advantage is how little it differs from PHP.” Like Facebook, these shops can gradually move their operations from one language to the another.

Michael Gardner
  • 6,406
  • 5
  • 21
  • 33