The Story Behind Flint, Facebook’s Open-Sourced Lint Program, Which Sniffs Out Bugs, Coding Errors

CodeOrange650To the average person, lint is something that gets caught by filters in clothes dryers, but to computer programmers, lint is actually helpful, as in lint programs, which help them sniff out bugs and coding errors in C programs. But why did Romanian C++ programmer and author Andrei Alexandrescu choose to write flint, Facebook’s lint program, in the D language? He explained the reasoning in a post on the Facebook engineering blog.

According to Alexandrescu, existing lint programs were too slow and did not support C++ 11 features that were already in use in the social network’s code base. Also, since Facebook would have had to “do extensive surgery” on any lint program it chose, in order to handle all of its needs, building its own program was the logical choice.

The result, flint, is the first D code base to be open-sourced by Facebook, and it issues lint errors so that programmers working on proposed code changes see warnings that appear automatically in the social network’s code-review system.

Alexandrescu goes into extensive detail in his blog post, and here are some highlights:

Lint programs are an odd class of program verifiers, and for a while, I wasn’t convinced that they were something I should focus on building out for Facebook. I don’t like the style police on my back, and false error warnings can trip up an entire task. There’s a lot of good, however, about a verifier that mechanically looks for issues that are not traditionally monitored by the compilers and that would almost always improve code quality once fixed.

Based on the principle of “simplest design that could possibly work,” flint is token-oriented, as opposed to building a parse tree. The linter loads the input file, converts it to an array of tokens, and then runs various analyses against that array. Each token saves the immediately preceding comment (if any), so comment information is preserved. Some of our lint rules require the use of stylized comments, as you’ll see below.

flint is written in the D language, making it the first D code base open-sourced by Facebook. In fact, our initial version of flint was written in C++; the D rewrite started as an experiment. From the measurements and anecdotes we gathered, the translation turned out to be a win on all fronts: the D version of the linter turned out smaller, dramatically faster to build, significantly faster to run, and easier to contribute to.

Image courtesy of Shutterstock.

Related Stories
Mediabistro Course

Marketing with Facebook Insights

Marketing with Facebook InsightsStarting October 2, learn how to use Facebook's analytics tool to track and optimize your marketing efforts! Taught by the group marketing manager of social media at Microsoft/BingAds, Geoffrey Colon will show you how insights works, how to measure key performance indicators, and make your data actionable. Register now!