Subscribe / Unsubscribe Enewsletters | Login | Register

Pencil Banner

Facebook uses functional programming to make News Feeds run smoothly

Joab Jackson | July 8, 2014
Facebook went with a novel programming methodology, called functional programming, to update the News Feed for its Apple iOS client, which helped considerably in tuning and debugging the app.

Using functional programming, a developer composes a program by assembling a series of functions. A functional program does not use the standard loops that a declarative program does and, once assigned a value, a variable cannot be changed — a design feature often called immutability.

The academic community has long championed functional programming as a superior technique, though until recently, it has never seen much usage in industry until recently. Ernst attributes the growing popularity to the use of multicore processors, which make it more difficult to program for, at least for complex programs, using standard declarative methods.

With the new Facebook iOS client — which has already been deployed on many user's iPhones and iPads — every new user interaction, even a simple "like," calls for the user's entire News Feed to be laid out again. This approach requires optimization to make the code run as quickly as possible. Getting the News Feed to run at an acceptable speed wasn't an insurmountable challenge for Facebook. And using functional programming dramatically reduced the effort required in debugging problems, Ernst said.

Nor was memory an issue.

One of the concerns around functional programming has been in the amount of memory a functional program can use — which often can be more than a standard decorative language. Ernst said this is not a concern. A photo taken on a device can take up megabytes of space, so in comparison, storing the text-based directory tree of a News Feed does not take up that much memory.

There have been a number of programming languages that are specifically designed for functional programming, some of which have been around for decades, such as Haskell, Lisp, Scheme, ML and, more recently, Clojure and Microsoft's increasingly popular F# language. Many other languages can be used for functional programming tasks, however, such as Java, JavaScript, Ruby, Scala, Python and Apple's recently launched Swift.

The team did not use a special functional language, such as Eiffel or Scheme, but rather Objective C++, a mixture of C++ classes and Apple's Objective C classes. C++ is what Ernst called a "multiple paradigm language," one able to support multiple programming models. So it supports functional programming as easily as it does as object oriented programming.

"It's definitely more challenging [writing functional in C++] compared to writing in a full functional language, but it also retains some familiarity for developers," Ernst said.

This is not the first use of functional programming for the social media giant. Elsewhere in the company, engineers developed React, a user interface library that is built on the functional architectural style. React inspired Ernst to try functional programming for his own task. Facebook engineers also developed and released Haxl, a Haskell library for querying data sets.


Previous Page  1  2  3  Next Page 

Sign up for MIS Asia eNewsletters.