Hack: a new programming language

Facebook developers released a PHP-powered language called Hack, which introduces enhancements and the proposed features originally dropped from PHP core.


Some of the powerful features of Hack

Type Annotations: allow for PHP code to be explicitly typed on parameters, class member variables and return values.

Generics: allow classes and methods to be parameterized (i.e., a type associated when a class is instantiated or a method is called) in the same vein as statically type languages like C# and Java).

Nullable Types: are supported by Hack through use of the ? operator. This introduces a safer way to deal with nulls and is very useful for primitive types that don’t generally allow null as one of their values, such as bool and int (using ?bool and ?int respectively). The operator can be used on any type or class.

Collections: enhance the experience of working with PHP arrays, by providing first class, built-in parameterized types such as Vector (an ordered, index-based list), Map (an ordered dictionary), Set (a list of unique values), and Pair (an index-based collection of exactly two elements).

Lambdas: offer similar functionality to PHP closures, but they capture variables from the enclosing function body implicitly and are less verbose.

Other significant features of Hack include Shapes, Type Aliasing, Async support, and more.