Last week, facebook announced that it had given its website, largely written in a programming language called php, a programming equivalent of a face lift. They also made a splash in the web development industry by releasing a new web programming language called Hack to the open source community. Hack is based on the php, but claims to keep “all the good parts” while removing some of its limitations. Since Facebook has been converting it’s legacy php to hack for some time now, you can trust that hack can stand up to the highest expectations, and that Facebook clearly has a lot of faith in the strength of the language.
Strengths (and Weaknesses) of PHP
PHP was designed to solve “The Web Problem,”or the challenges inherent in the creation of dynamically generated applications and pages on the Internet. Unlike most programming languages, PHP was designed to function within the challenges of Internet development, which include statelessness, heterogeneousness, typelessness, and the short shelf life of transactions. In those types of conditions, you want a “loosely typed” language like php.
“Loosely typed” refers to how you declare variables, and means that you don’t have to specify what type of data that will be stored in a variable when it is created. This allows you to plan less up front and code faster. This works great in protoyping situations that facebook favors, but has led to the notion that PHP is useful only in a prototyping capacity: that it’s easy to build an application quickly but challenging to build an application quickly and maintain it as it grows.
This was facebook’s challenge. With facebooks millions of pages and global reach, writing sound php code was getting unwieldy, and it became apparent that there were benefits a more strongly typed language (type defined variables) could provide in terms of stability. Facebook is a huge proponent of the hacker culture, favoring slaping something together fast and dirty so they can focus on the innovation, but were hitting a wall. Instead of risking a complicated rewrite of the social media platform, They built hack to be like php but with the option to strongly type variables or loosely type them, without changing the feel of the language.
Hack, the Best of Both Worlds
You can think of Hack as a new version of PHP. 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,” says Bryan O’Sullivan, one of the three facebook engineers that built Hack.
Will Hack Shift the Web Development Paradigm?
PHP be has typically been criticized by developers in other programming languages as “sloppy, inconsistent code.” With the ability to define as much as you want, this may encourage more people to use Hack than PHP. If more gradually typed languages begin to emerge, it will be better for developers who will be able to create and test faster, while also being better for their users, who will have a more stable, less buggy application. I want to try it out!