Facebook open-sources Hack code generator

Hack Codegen creates code for Facebook's PHP spinoff

Facebook open-sources Hack code generator
Credit: Thinkstock

Continuing with its open source endeavors, Facebook has open-sourced Hack Codegen, a library for automatically generating Hack code.

Hack is Facebook's spinoff of the PHP language, working with the HHVM virtual machine. The library, meanwhile, generates code that is written into signed files to prevent undesired modifications. "The idea behind writing code that writes code is to raise the level of abstraction and reduce coupling," Facebook said on its GitHub page for Hack Codegen.

"Being able to generate code through automated code generation allows programmers to increase the level of abstraction by making frameworks that are declarative and that are translated into high-quality Hack code," said Facebook software engineer Alejandro Marcu, in a blog post. "We've been using Hack Codegen at Facebook for a while. After seeing so much internal success, we open-sourced this library so that more people could take advantage of it."

Prior to building Hack CodeGen, Facebook mainly generated code through concatenating strings and a helper functions. "We realized early on that we would need a good library to generate code, since concatenating strings to generate code don't really scale," Marcu said. "At the time, we didn't do that much code generation at FB, mostly dumping values into arrays, so we didn't have any good tools except for signing files."

Facebook has been on an open-sourcing spree, offering such technologies as its Nuclide IDE for Web and native mobile development, its React Native JavaScript software, and the ComponentKit iOS UI development framework to open source. Facebook’s Parse group, meanwhile, plans to make its SDKs available via open source.

This story, "Facebook open-sources Hack code generator" was originally published by InfoWorld.

To comment on this article and other CIO content, visit us on Facebook, LinkedIn or Twitter.
Download the CIO Nov/Dec 2016 Digital Magazine
Notice to our Readers
We're now using social media to take your comments and feedback. Learn more about this here.