Thursday, April 10, 2014

Facebook Introduces ‘Hack,’ the Programming Language of the Future



Jon Snyder/WIRED



Facebook engineers Bryan O’Sullivan, Julien Verlaguet, and Alok Menghrajani spent the last few years building a programming language unlike any other.
Working alongside a handful of others inside the social networking giant, they fashioned a language that lets programmers build complex websites and other software at great speed while still ensuring that their software code is precisely organized and relatively free of flaws — a combination that few of today’s languages even approach. In typical Facebook fashion, the new language is called Hack, and it already drives almost all of the company’s website — a site that serves more than 1.2 billion people across the globe.
“We can say with complete assurance that this has been as battle-tested as it can possibly be,” says O’Sullivan, a veteran of iconic tech companies Sun Microsystems and Linden Lab who has long played an important role in a popular language called Haskell.
O’Sullivan and company publicly revealed their new language this morning, and at the same time, they “open sourced” it, sharing the technology with the world at large and encouraging others not only to use it, but to help improve it.
The software world is littered with programming languages, and new ones appear all the time. But according to some who have used it or who know the past work of those who built it, Hack has a design and a pedigree that immediately set it apart. “If Bryan O’Sullivan built it,” says programming guru David Pollak, who only yesterday heard about the new language, “I would walk across hot coals to use it.”

In the Beginning

When Mark Zuckerberg started work on Facebook in late 2003 — a moment recreated to such great effect in the Hollywood film The Social Network — he used a programming language called PHP. It was one of the most popular web languages of the day — a language that let you build and rebuild sites with extreme speed. PHP is what’s called a dynamically typed language. Basically, this means you needn’t take the time to define specific parameters for each and every routine in your code, and once you finish a piece of code, you can almost instantly run it — without taking additional time to compile it into another form. The code essentially compiles in the background, as you write it.
The new language is called Hack, and it already drives almost all of the company’s website — a site that serves more than 1.2 billion people across the globe.
For the next decade, Zuckerberg and his rapidly growing company continued to build their site with PHP. It suited “The Hacker Way,” the Zuckerberg coding philosophy that encourages engineers to constantly look for ways of improving the technology at hand. But eventually, as Facebook expanded to hundreds of millions of people, the language started to show its limitations. As a PHP site grows, you need far more computer servers to run the thing than you would with other languages, and it can be difficult to manage all your code and keep it free of bugs.
At a certain size, you’re better off with statically typed languages such as Java, where you’re required to carefully define your variable types. You can’t move as fast with these languages — you have to compile code before running it — but you need fewer servers to run your code, and in the long run, it’s easier to manage what you’ve built.
Last year, after a brainstorm from three top engineers, Facebook solved the server problem by running all its PHP code on a new software creation called HHVM, short for Hip Hop Virtual Machine. HHVM was a new foundation for the Facebook website, letting the company run its site on significantly fewer machines. Now, with Hack, their new programming language, Bryan O’Sullivan and his tiny team have solved the other problem. Hack makes it easier to manage code and eliminate errors.
“It arose out of a desire to improve the efficiency of our developers,” says the Irish-born O’Sullivan. “As our engineering team grew, their own jobs were becoming more complicated because PHP is a dynamically typed language. It made it harder for them to easily apprehend the consequences of some of the work they were doing.”

The New PHP

You can think of Hack as a new version of PHP. It too runs on the Hip Hop Virtual Machine, but it lets coders use both dynamic typing and static typing. This is what’s called gradual typing, and until now, it has mostly been an academic exercise. Facebook, O’Sullivan says, is the first to bring gradual typing to a “real, industrial strength” language.
What this means is that Facebook was able to gradually replace its existing PHP code with Hack — move from the old dynamically typed system to a statically typed arrangement. “It allows you to slide the dial yourself on the continuum between dynamic types and statics — so you can start out with dynamically typed code and then gradually add more statically typed code, benefiting from each little bit of work you do as you go along,” O’Sullivan says.
In doing so, he explains, Facebook built much more precise code — code with fewer flaws. Hack provides a kind of safety net for developers. What’s more, engineers can more easily understand code when they revisit it. Static typing acts a lot like documentation.
But the big trick is that Hack provides these benefits without slowing down the developer: Unlike other statically type languages, Hack can run without compiling. “You edit a file and you reload a webpage and you immediately get the feedback of: Here’s what the page looks like after I made that change. There is no delay,” O’Sullivan says. “You get both safety and speed.”
hack screen
Nils Adermann, a software engineer and the co-founder of a company called Forumatic, has used the language, and he says he knows of nothing else quite like it. James Miller and Simon Welsh, engineers at a company called PocketRent, who have also used Hack, agree. The closest thing, they say, is Haskell, a statically typed language that provides a way of executing code relatively quickly. But Hack, they indicate, takes the idea much further.
Hack will be particularly attractive, Adermann says, to existing PHP shops. “Ironically,” he says, “its chief advantage is how little it differs from PHP.” Like Facebook, these shops can gradually move their operations from one language to the another. But Adermann also believes that some developers will adopt the language even if they’re not already using PHP. “While PHP is the most widely used language on the web, it’s unpopular in many places because of its inconsistencies,” he says. “Hack addresses these … and thereby makes the language more attractive to users of other languages.”
But the biggest endorsement for the new language is that Facebook already uses it to run its own site, the world’s most popular social network. It’s not every day that a new language debuts with such an impressive track record. Some, however, question whether Hack should really be called a new programming language. There’s a fine line here between an update to PHP and a replacement for PHP. Where does Facebook draw that line? “That,” Sullivan says, “is a good question to discuss late at night over whiskeys.”

0 comments: