PHP Evolved: Facebook's New Hack Programming Language
Facebook's propensity for PHP is fairly well-known. Dating back to the company's early days, PHP has powered many of the company's offerings. One of PHP's strengths is that it is a dynamic language well-suited to rapid prototyping, but this same attribute tends to complicate the development and maintenance of large code bases. To address these concerns, Facebook has released Hack, a new programming language intended to maintain PHP's strengths while augmenting this with what they call gradual-typing and several new language features.
This use of gradual typing means in Hack dynamic and statically-type code can inter-operate in the same file. This lets existing PHP code be converted to Hack according to the needs of each project it is used in without requiring a large up-front conversion cost. To assist with a PHP to Hack migration, Facebook is providing conversion tools. Hack itself works by monitoring your source file as you edit it. A system daemon monitors your local filesystem, and when changes are saved to disk a type checker will quickly analyze the changes. Facebook indicates that this turnaround averages 200ms and should rarely exceed 60 seconds.
Hack isn't just bringing typing characteristics, it is also providing several additional language features. These include type annotations, nullable types, generics, collections, and lambdas. The Hack language reference provides full details on all features currently available. Just like the PHP code at Facebook, Hack runs on Facebook's Hip Hop Virtual Machine (HVVM) which uses just-in-time compilation to boost program performance.
For more background on PHP at Facebook, InfoQ published an interview with Facebook's Keith Adams this past December.
Hack Language Tutorial
Caitie McCaffrey Apr 24, 2015