Facebook's Hack Language Speeds Up Development Cycle

Janet Wagner, Data Journalist / Full Stack Developer
Apr. 10 2014, 08:00AM EDT

Facebook has released an open source version of Hack, a programming language developed by Facebook that targets HipHop Virtual Machine (HHVM) and is designed to interoperate seamlessly with PHP. Hack was built to maintain the fast PHP development cycle while allowing for addition of features available in other modern programming languages.

Hack is considered a "gradually typed" programming language created for HHVM, an open source virtual machine capable of running programs written in Hack and PHP. Launched in December 2011, Facebook's HHVM is a PHP runtime and uses just-in-time (JIT) compiler functionality to ensure the highest performance. HHVM is capable of running many of the popular PHP frameworks including codeigniter, composer, mustache, phpmyadmin, symfony, and more.

Hack

The Hack programming language is written primarily in OCaml, a varient of Caml, because of OCaml's high performance and ability to easily target JavaScript. It can interoperate well with C. (Some of Hack is written in C). Features available in Hack include (but are not limited to):

  • Gradual typing: This feature allows developers to use dynamic typing and static typing, both of which seamlessly interoperate. Hack is designed for incremental adoption.
  • Generics: Classes and methods can now be parameterized using PHP. Hack documentation defines parameterized as "a type associated when a class is instantiated or a method is called."
  • Collections: Designed to work with static typing and generics, collections can be used as an alternative to PHP arrays. Hack features built-in parameterized collections including vectors, maps, sets and pairs.
  • Nullable: Hack allows a null value to be assigned to any type or class using the ? operator. Null is often a problem for developers using PHP.
  • Trailing commas: A trailing comma is a valid syntax in Hack and is often used for multiline arrays. The trailing comma allows the addition of new elements at the end of an array.

Hack was created to enable quick platform efficiency and performance improvements at Facebook scale. It addressed one of the challenges of using PHP—it is not designed to be heavily optimized, especially for platforms at a scale the size of Facebook.

Julien Verlaguet, software engineer at Facebook and tech lead on Hack, who explained to ProgrammableWeb why Hack was created:

At Facebook, we've used PHP since the creation of thefacebook.com, which has allowed us to build and improve quickly. But even with improvements afforded by HHVM, operating efficiently at our scale, and within our culture of moving fast, continued to be a challenge. So we built, open-sourced, and converted our code base to Hack, a programming language that finds the sweet spot between static and dynamic languages—you get all the benefits of static languages like safety, refactorability, and surfacing errors without losing iteration speed.

Late last year, Julien Verlaguet gave a presentation titled "Hack for HipHop" at the Commercial Users of Functional Programming (CUFP) 2013 Conference. He introduces Hack and talked about scaling PHP, Hack types, working at scale and other aspects of the Hack programming language. Verlaguet's presentation at CUFP 2013 marked the first time Hack was discussed publicly.

"What is very important for Facebook is a very fast incremental loop," Verlaguet said during the presentation. "If you introduce a type system over millions of lines of code that is too slow, nobody is going to use it and it's not going to be a very successful project."

In addition to developing Hack features that improve performance, Facebook software engineers have also built several APIs for Hack, including a Collections API and Extension APIs. According to a blog post written by Bryan O'Sullivan, engineering manager at Facebook, a collections system was built for Hack. The collections system is a set of "modern APIs for dealing with bulk data." Lambda expressions, an HHVM feature that provides functionality similar to PHP closures, can be used to make the most of the Collections API.

Related Searches From ProgrammableWeb’sDirectory of More Than 10,000 APIs

Browse the full directory

Facebook plans to develop and improving Hack over the long term, Verlaguet says:

We've already seen great success with Hack at Facebook, and over the past year, we've migrated nearly our entire code base to Hack. Additionally, the combo of Hack and HHVM virtually eliminates compile times. Hack is just the beginning, and we will continue to evolve both Hack and HHVM. We're eager to work together with the PHP community to make this better and shape the future of PHP.

Yesterday was Hack Developer Day at Facebook headquarters, an all-day event featuring the introduction of the Hack programming language. The event includes a late afternoon / evening Hackathon where developers were encouraged to work with the designers and engineers behind Hack and HHVM.

For more information about HHVM and Hack, visit HHVM.com.

By Janet Wagner. Janet is a data journalist and full stack developer based in Toledo, Ohio. Her focus revolves around APIs, open data, data visualization and data-driven journalism. Follow her on Twitter, Google+ and LinkedIn.

Janet Wagner Janet is a data journalist and full stack developer based in Toledo, Ohio. Her focus revolves around APIs, open data, data visualization and data-driven journalism. Follow her on Twitter: @webcodepro and on Google+

Comments