Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How would you migrate from PHP to Hack? [closed]

Tags:

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?

like image 680
Ronni Egeriis Persson Avatar asked Mar 20 '14 17:03

Ronni Egeriis Persson


People also ask

Is Hack compatible with PHP?

Hack is mostly backward-compatible with PHP code, although it extends the PHP language with strict typing, new data structures, and a real-time type checking server. That being said, Hack's own developers prefer to call Hack a dialect of PHP and not a new language.

What is the difference between PHP and Hack?

Hack is built from the ground up to enable static type checking, with features PHP lacks like generics, shapes, enums, hack arrays, and a well-typed standard library to enable rigorous static analysis.

Does HHVM support PHP?

HipHop Virtual Machine (HHVM) is an open-source virtual machine based on just-in-time (JIT) compilation that serves as an execution engine for the Hack programming language and used to support PHP execution before the release of HHVM version 4.

What is HHVM used for?

HHVM is an open-source virtual machine designed for executing programs written in Hack. HHVM uses a just-in-time (JIT) compilation approach to achieve great runtime performance while maintaining amazing development flexibility. HHVM supports the Hack programming language.


2 Answers

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.

like image 90
Josh Watzman Avatar answered Oct 02 '22 05:10

Josh Watzman


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.

like image 35
Michael Gardner Avatar answered Oct 02 '22 06:10

Michael Gardner