Fast Development
Fast Development
Hack 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.
Type Checking
Type Checking
Hack provides instantaneous type checking by incrementally checking your files as you edit them. It typically runs in less than 200 milliseconds, making it easy to integrate into your development workflow without introducing a noticeable delay.
Built for HHVM
Built for HHVM
Hack is built specifically for HHVM, a high performance runtime for your Hack applications.
Watch Our Introduction to Hack Video!
Hack is a programming language developed by Meta. It lets you write code quickly, while also having safety features built in, like static typechecking.
<<__EntryPoint>>
async function my_example(): Awaitable<void> {
$user_ids = vec[1, 2, 3];
// Initiate all the database requests together,
// so we spend less time waiting.
$user_names = await Vec\map_async(
$user_ids,
async ($id) ==> await fetch_user_name($id),
);
// Execution continues after requests complete.
echo Str\join($user_names, ", ");
}
async function fetch_user_name(
int $_,
): Awaitable<string> {
// This could be a database request.
return "";
}
Async
Asynchronous operations allow cooperative multi-tasking. Async functions can combine I/O requests, making your code faster.
Generics
Hack supports a rich set of generic types, including type parameters, constraints, associated type constants and even reification.
class Box<T> {
protected T $data;
public function __construct(T $data) {
$this->data = $data;
}
public function getData(): T {
return $this->data;
}
}
// Traditional: Risky and easy to misplace tags!
$user_name = 'Fred';
echo "<tt>Hello <strong>$user_name</tt></strong>";
// XHP: Typechecked, well-formed, and secure
$user_name = 'Fred';
$xhp = <tt>Hello <strong>{$user_name}</strong></tt>;
echo await $xhp->toStringAsync();
XHP
XHP provides a native XML-like representation of output (e.g., HTML) and allows UI code to be typechecked, automatically avoiding several common issues like cross-site scripting (XSS) and double-escaping.
XHP is safe by default: All variables are automatically escaped in a context-appropriate way.
Collaboration, Research, and Usage
HHVM and the Hack language are in active development. We are moving fast, making changes daily and releasing often. If you notice a regression in the typechecker or the runtime, please open issues when you find them.
Academic literature and recent research can be found below.
- Jump-Start: Jump-Start improves the performance of virtual machines at scale and has successfully been implemented in the HipHop Virtual Machine (HHVM), which powers not only Facebook.com but also many other sites across the web.
- Zoncolan: Facebook’s web codebase currently contains more than 100 million lines of Hack code, and changes thousands of times per day. With Zoncolan and its static analysis capabilities, security engineers scale their work by automatically examining Hack code and proactively detecting potentially dangerous security or privacy issues.