Hack: Facebook Open-Sources Programming Language


By David Cohen 

Hack650The word “hack” is an integral part of Facebook’s culture, so it should come as little surprise that a programming language it developed for HHVM that integrates seamlessly with PHP, which it announced the open-sourcing of Thursday, is called Hack.

The social network said in a post on its engineering blog that it migrated its entire PHP code base to Hack over the past year, adding that the programming language “resolves the fast development cycle of PHP with the discipline provided by static typing,” while adding features from other, modern programming languages.

Software Engineer Julien Verlaguet and Security Engineer Alok Menghrajani wrote in the blog post:

Every PHP programmer is familiar with day-to-day tasks that can be tricky or cumbersome. The code below is a great example of a common mistake where a method could unexpectedly be called on a null object, causing an error that would not be caught until runtime. Another example is a complex application-programming interface, where developers may have a solid understanding of its semantics but still spend time looking up mundane method names in documentation.

With thousands of engineers working on millions of lines of code at Facebook, these challenges scaled up. We had a simple language with a quick feedback loop, but could we mitigate the sorts of problems described above? Could detecting errors coexist with rapid iteration, all while preserving our investment in PHP? Could improved code analysis and introspection help make developers more productive with tools like autocomplete?

Traditionally, dynamically typed languages provide rapid development while sacrificing the ability to catch errors early and introspect code quickly, particularly on larger code bases. Conversely, statically typed languages provide more of a safety net, but often at the cost of quick iteration. We believed there had to be a sweet spot.

And, thus, Hack was born. We believe that it offers the best of both PHP and statically typed languages, and that it will be valuable to projects of all sizes.

We are delighted to open-source both Hack and the tools that we used to convert our code base. We believe this is the beginning of an exciting journey, and we are dedicated to making software development ever easier for both our own engineers and the broader community. Hack’s value is not limited to big projects: With type information, good error messages, and fast feedback, small code bases can reap the benefits of Hack, as well.

Next month, we will also introduce the language at the Hack Developer Day on the Facebook campus in Menlo Park, Calif., and we hope to see you there in person or online.