Paul Krill
Editor at Large

Facebook open-sources Hack code generator

news
Aug 25, 20152 mins

Hack Codegen creates code for Facebook's PHP spinoff

conceptual image of hand on keyboard with code raining down from above
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.

Paul Krill

Paul Krill is editor at large at InfoWorld. Paul has been covering computer technology as a news and feature reporter for more than 35 years, including 30 years at InfoWorld. He has specialized in coverage of software development tools and technologies since the 1990s, and he continues to lead InfoWorld’s news coverage of software development platforms including Java and .NET and programming languages including JavaScript, TypeScript, PHP, Python, Ruby, Rust, and Go. Long trusted as a reporter who prioritizes accuracy, integrity, and the best interests of readers, Paul is sought out by technology companies and industry organizations who want to reach InfoWorld’s audience of software developers and other information technology professionals. Paul has won a “Best Technology News Coverage” award from IDG.

More from this author