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."