Anytime a new language comes out it’s fun to immediately download it and give it a try. Yesterday Facebook announced Hack, a programming language they developed for HHVM which interoperates seamlessly with PHP. Facebook itself is already running on Hack, and it looks to deliver some exciting improvements from its PHP influence, we thought we’d make it a bit easier for you to run your own apps on Hack by working with them to create a Heroku buildpack. To highlight a few of the awesome things about Hack:
- Many PHP files are already valid Hack, so you can just start with an existing PHP project
- Gradual typing, which lets dynamic and statically typed code play well together
- More language features including: collections, lambdas, and run-time enforcement of return types and parameter types
Of course you can read much more about Hack over on Facebook's announcement.
Just like everyone else we were excited to see and play with hack. After installing system dependencies and giving Hack a spin we wanted to get it running in production. Throughout this process we had the privilege of spending the afternoon over at Menlo Park with the team, we took advantage of this to make things a little easier we worked with the Hack and HHVM teams to create a HHVM/Hack buildpack that you can try right now.
Let’s take a try at creating a basic hello world in hack and getting it deployed. First create your
index.php as follows:
<?hh echo "Hello from HHVM ".HHVM_VERSION;
Then let's create our git repo, add the file, create our Heroku app and deploy away:
$ git init . Initialized empty Git repository in /tmp/myhackapp/.git/ $ git add index.php $ git commit -m 'initial' [master (root-commit) 024f2b1] initial 1 file changed, 3 insertions(+) create mode 100644 index.php $ heroku create --buildpack https://github.com/hhvm/heroku-buildpack-hhvm Creating stormy-crag-8213... done, stack is cedar BUILDPACK_URL=https://github.com/hhvm/heroku-buildpack-hhvm http://stormy-crag-8213.herokuapp.com/ | firstname.lastname@example.org:stormy-crag-8213.git …
And then we can check and see that it worked:
$ heroku open
Now you can both easily play with hack and hhvm, and deploy it for sharing and collaborating with others. Give it a try and let us know what you think.