Hack is a type-safe programming language developed and open-sourced by Meta (formerly Facebook). It’s designed to improve developer productivity, combining the speed and flexibility of PHP with modern programming features like static type checking. Hack runs on the HHVM (HipHop Virtual Machine), ensuring excellent performance and scalability.
Hack introduces a gradual typing system, empowering developers to:
- Catch bugs early with static type-checking.
- Refactor code safely while maintaining flexibility.
- Leverage modern features like async programming, collections, and generics.
Hack allows you to incrementally add types to an existing PHP codebase, making it ideal for large-scale applications.
-
Gradual Typing
Migrate seamlessly from dynamic to static typing. Add types where needed. -
Advanced Type System
Supports generics, nullable types, and collections to write safer, clearer code. -
Asynchronous Programming
Useasync
andawait
for non-blocking code execution, ideal for I/O-bound tasks. -
High Performance
Powered by HHVM, Hack achieves fast execution speeds for web-scale applications. -
Codebase Compatibility
Designed for easy interoperability with existing PHP codebases.
- HHVM (HipHop Virtual Machine) is required to run Hack.
Install HHVM from https://hhvm.com/.
# On Debian/Ubuntu
sudo apt-get install hhvm
Create a file named hello.hack
:
<?hh
<<__EntryPoint>>
function main(): void {
echo "Hello, Hack!\n";
}
Run the script:
hhvm hello.hack
Explore the official documentation to learn more about Hack:
- Hack Docs: https://docs.hhvm.com/hack/
- HHVM Docs: https://docs.hhvm.com/
Hack is extensively used within Meta (Facebook) to power mission-critical applications. It has proven its capabilities in handling billions of requests daily at a global scale.
Hack is open-source and welcomes contributions from the community. Get involved by visiting the repository:
GitHub: https://github.com/facebook/hhvm