Facebook Q&A: Hack brings static typing to PHP world

Julien Verlaguet, a designer of the Facebook-driven language, talks about how Hack marries static typing with the benefits of fast PHP development

The Hack language, which brings static typing to the dynamically typed PHP realm, recently was released by developers at Facebook, who have linked the language to Facebook's HipHop Virtual Machine (HHVM) for PHP. Already deployed at Facebook, Hack has been the work of engineers Julien Verlaguet, Alok Menghrajani, and a team of developers.

InfoWorld Editor at Large Paul Krill recently spoke with Verlaguet, who is a designer of the language and a tech lead for languages and tools at Facebook, about the intention of Hack and where the language goes from here.

InfoWorld: What is the purpose of Hack?

Verlaguet: What is happening is that Facebook started using PHP because PHP has a very fast feedback loop and that's something you want. It's extremely valuable when you are building a website. What it means is that when you're writing your program, the code -- when you're editing it, when you're changing it -- the time it takes to try your change and run it is very, very [minimal]. That's extremely valuable and that's something that we wanted to keep.

However, dynamically typed languages in general -- and that's not a problem just with PHP -- they offer [fewer] guarantees, like static guarantees. What it means is that there is an enormous amount of tooling available for programmers that check that your program is correct in other languages, in languages known as statically typed, such as Java. Tools such as a type checker, they provide a safety net in the sense that they're going to find errors in your program before you even run it. That's the kind of thing we were interested in building for Facebook, and that's why we developed Hack, which is a language that is compatible with PHP but adds static typing and other language features that make the life of developers easier.

InfoWorld: What other features?

Verlaguet: One important contribution from [Hack team member] Drew Paroski is collections. Collections are designed to replace arrays. PHP arrays are useful, but they have had too many use cases and some of them can be misleading for programmers. What Drew did is that he took all these use cases and designed a collection API that was separating them in clean subsets. So now you have an object set, an object vector, an object map that is specialized for each use case, while arrays were used for everything before that.

InfoWorld: Hack compiles to the HHVM?

Verlaguet: [Hack] runs on the exact same [HHVM] virtual machine indeed. That's why it tends to operate very well with PHP because HHVM was designed to run PHP, so the two interoperate seamlessly. What it means is that from Hack code you can call PHP code and PHP code can call Hack code and it's all compatible.

InfoWorld: Where have you used Hack in Facebook?

Verlaguet: We converted nearly all of our [PHP] code base to Hack.

InfoWorld: What's the next step for Hack? Is there a 1.0 version coming out?

Verlaguet: We still have plenty of things to do on the language itself. We have to keep aware of the fact that for now it's a tool for Facebook. Now that we have open-sourced it, we need to take into account the feedback of the new users who are going to try to use Hack for their own needs and we are probably going to spend some time doing that. People are going to try Hack on their own projects. They're going to have problems because they are probably using PHP and Hack in a different way than we do it at Facebook and we will have to go after these problems one after another. So that's what I expect is happening. When we are comfortable with the version that we have, I hope we can [offer] a first stable release.

InfoWorld: When do you think that might happen?

Verlaguet: It depends how much adoption we get. If we have a lot of feedback, a lot of people engaging, it could be a few months. It will depend on how many people engage [and the number of problems found]. That's very hard to predict.

This story, "Facebook Q&A: Hack brings static typing to PHP world," was originally published at InfoWorld.com. Get the first word on what the important tech news really means with the InfoWorld Tech Watch blog. For the latest developments in business technology news, follow InfoWorld.com on Twitter.


Copyright © 2014 IDG Communications, Inc.

How to choose a low-code development platform