The Scoop on Facebook’s New Hack Programming Language

Originally developed by Facebook in 2011, HipHop Virtual Machine (HHVM) is a virtual machine that’s intended for the execution of programs written in Hack and PHP. Featuring a special type system known as “gradual typing,” it supports the use of both dynamic and static typing. Because of this dual-purpose system, programmers can define types for functional arguments, return values and class properties (local variables cannot be specified).

While most programmers are familiar with PHP, they may not know about Hack — one of the languages supported by Facebook’s HHVM. So, what in the world is Hack and how does it work?

The Basics of Hack and How it Works

Hack is an open-source general-purpose programming language that was created by Facebook in 2014. It works seamlessly with PHP, extending the traditional type hinting that is currently available in PHP 5 with the addition of static typing. Because it uses a gradual typing system annotations are not not required. According to the official website, the language “…reconciles the fast development cycle of a dynamically typed language with the discipline provided by static typing, while adding many features commonly found in other modern programming languages.”

One of the greatest perks of Hack is its ability to check files almost instantly. It typically runs in under 200 milliseconds, allowing programmers to integrate Hack scripts into their projects without causing any delay or slowdown of progress.

Here’s an example of basic Hack script, complete with the opening tag:

echo 'This is my script';

As you can see, the Hack code above contains the opening tag of <?hh instead of the <?php tag that is used for PHP.

Some of the features of Hack include the following:

  • Type Annotations — allows code to be types on parameters, class member variables and return values.
  • Generics — used to paramaterize classes and methods, similar to static languages like C# and Java.
  • Nullable Types — often used for dealing with nulls.
  • Collections — first class, parameterized types like Vector, Map, Set, Pair.
  • Lambdas — allows for the definition of first-class functions.
  • XHP — offers a native XML representation of the output, allowing the user interface code to be typechecked; thus, avoiding issues like cross-site scripting and double-escaping.

Note: unlike its PHP counterpart, Hack cannot be used in conjunction with HTML code. Hack can, however, be used in XHTML code.

You can learn more about Facebook’s Hack programming language by accessing the official documentation here.

Thanks for reading, follow your passion by finding the perfect course, just for you over on

(Visited 167 times, 1 visits today)