There is a clever combination of language and platform development rolling out of Facebook engineering in the form of HHVM and the Hack programming language—and what is working for production users of this code base inside Facebook, is also powering production jobs at Baidu, Box, and Wikipedia.
“With static languages, the code is written, then something checks to make sure the code is correct typing-wise. With dynamic languages, you run the code directly and figure out at runtime if something went wrong. But Hack is somewhere in between the two—it’s a gradually typed language, so it’s the programmer’s decision to use it statically or dynamically and all at a fine-grained level, even for each function if desired,” says Julien Verlaguet, software engineer at Facebook.
While Verlaguet might be slightly oversimplifying the choices between languages, the fact is, having the ability to take shortcodes based on the needs of the code—and do so on a platform that is fully cognizant of the code base running on HHVM comes in handy, providing some speedups that could extend conceptually to other programming environments. For instance, The point of Hack is not so much about the language, but rather the iterative cycle between writing a line of code and seeing the change on the front end. “With statically typed languages requiring a check, there is a wait time and that is not efficient. We want to preserve the velocity for developers—allow refresh and see changes immediately.” He says that the approach of Hack on HHVM is not a binary that is run from the command line. Rather, the Hack type checkers is a daemon that runs in the background and watches the file system. So when it starts up, it takes all the files in, then whatever is changed on the file system will be recognized on the background server, which refreshes everything—meaning the checks are nearly instant (within the tens of milliseconds) and the tooling around it comes with that quick turnaround because it is aware of the whole codebase.
In terms of other “shortcuts” that cut down on inefficiencies of systems on the development side, there is the tricky matter of error messages. To get out of the weeds on this topic, in most cases, fixing code problems requires a still very manual slog through the code with testing, debugging and editing. This takes time. But with Hack, the error is written in yellow, the code that needs to be fixed is highlighted automatically, and the system brings the developer directly to the place that needs to be modified.
Another element of Hack on HHVM that could be useful in other development environments is that it hacks through the inefficiencies of wasting time waiting on the CPU. There is always a time where data is being fetched from somewhere like a database where you’re stuck on I/O, Verlaguet explains. There are already some ways to get around that wait time and perform other operations, but Hack makes it simpler to fetch other elements and reorder the operations based on what comes back for more efficient operations. Verlaguet notes that the time-saving potential here adds up at scale—which is what defines many of Facebook’s development projects that have found their way into more mainstream enterprise worlds—adding efficiency at scale.
On that note, it seems like Hack and HHVM are setting the tone for a new way of approaching programming. One that is less defined by big decisions that set the course (taking a static versus dynamic language approach, for instance). The expectation is that as Hack gathers development steam, it will do far more than extend the reach of PHP based services. “People don’t realize just how extensively this is used at Facebook. It’s really the de facto service side language here,” says Verlaguet, who points to some core differentiation in Hack running on HHVM over other approaches. He says that for anyone who works at Facebook, this is the way development is conceptualized—and it’s likely that we’ll see more such approaches to programming as the march of web-scale tools find their way into the broader world.
Sign up to our Newsletter
Featuring highlights, analysis, and stories from the week directly from us to your inbox with nothing in between.