The Complete Magazine on Open Source

‘Hack Codegen’, A Code That Writes Code, Is Now Open Source

, / 240 0
Hack Codegen comes from the house of Facebook.

In a recent initiative that supports open source technologies, Facebook has decided to open source hack Codegen, which is a software, designed to write code. In a blog post, Facebook explained the motivation behind creating Hack Codegen, saying, “Before Hack Codegen was developed, we mainly generated code through concatenating strings and a few helper functions. On the product infrastructure team at Facebook, we had been looking into how to improve one of our internal systems for reading and writing data.”

Making an announcement about open sourcing Hack Codegen, Facebook shared, “Hack Codegen is a library for generating Hack code and writing it into signed files that prevent undesired modifications. 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. 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. ”

Hack code is Facebook’s programming language developed for HipHop Virtual Machine (HHVM). According to the official website, Hack is a programming language for HHVM. Hack reconciles the fast development cycle of a dynamically typed language with the discipline provided by static typing, while adding many features commonly found in other modern programming languages.

Hack provides instantaneous type checking by incrementally checking your files as you edit them. It typically runs in less than 200 milliseconds, making it easy to integrate into your development workflow without introducing a noticeable delay.

Before hack Codegen came into being, Facebook used to generate code via concatenating strings. The social media company later discovered that this technique was not good enough to scale up. Facebook wrote, “We realised early on that we would need a good library to generate code. At the time, we didn’t do that much code generation at [Facebook], mostly dumping values into arrays, so we didn’t have any good tools except for signing files. This is the need that motivated us to write this library.”

Lack of scaling lead Facebook engineers to work on Hack Codegen project. Due to the organisc adoption and homegrown refactoring tools, Facebook migrated almost all of its PHP codebase to hack on over a year and a half. Facebook said, “After seeing so much internal use of Hack Codegen for diverse applications, it’s our pleasure to open source this library for the external community to use.”

“It is interesting that we are getting back into automated code generation which was a big deal in a different era. Codegen is a valuable new tool that can help developer productivity in the right settings. The issues for automated code generation have typically been learning the abstraction itself, and then the ability to accommodate changes in the generated code. Newer technologies are constantly innovating around these issues,” it added.