Learn Hack - 10 Code Examples & CST Typing Practice Test
Hack is a programming language developed by Facebook as a dialect of PHP. It adds static typing, enhanced performance, and modern programming features while maintaining compatibility with PHP, enabling rapid development of large-scale web applications.
Learn HACK with Real Code Examples
Updated Nov 20, 2025
Explain
Hack combines dynamic typing of PHP with optional static typing.
It allows gradual typing, meaning developers can mix typed and untyped code.
Designed for web development at scale, particularly within the Facebook ecosystem.
Core Features
Gradual typing system
Async programming with awaitables
Generics and type annotations
Shape types for structured data
Hack collections (vec, dict, keyset)
Basic Concepts Overview
Gradual typing (dynamic + static)
Collections (vec, dict, keyset)
Async programming with awaitables
Functions, classes, and traits
Shapes and generics for structured data
Project Structure
src/ - main Hack codebase
lib/ - reusable libraries
tests/ - unit and integration tests
docs/ - project documentation
configs/ - HHVM and server configurations
Building Workflow
Write Hack code with optional types
Run using HHVM interpreter or server
Test functions, classes, and async tasks
Compile or run scripts for production
Integrate with PHP code if necessary
Difficulty Use Cases
Beginner: small Hack scripts and functions
Intermediate: collections and async functions
Advanced: generics, shapes, and type-safe code
Expert: large-scale web application architecture
Migration: PHP to Hack gradual typing adoption
Comparisons
Adds static typing to PHP
Runs on HHVM instead of standard PHP engine
Better for large-scale web applications
Supports async and modern language features
Smaller ecosystem than mainstream PHP
Versioning Timeline
2014 - Hack created by Facebook
2015 - HHVM integration stabilized
2016 - Async programming and collections introduced
2018 - Generics, shapes, and typechecker improvements
2020s - Ongoing maintenance and ecosystem updates
Glossary
Gradual typing: mix of static and dynamic types
HHVM: HipHop Virtual Machine for Hack/PHP
Collections: vec, dict, keyset types
Awaitable: async result to be awaited
Shape: structured data type with fixed fields
Frequently Asked Questions about Hack
What is Hack?
Hack is a programming language developed by Facebook as a dialect of PHP. It adds static typing, enhanced performance, and modern programming features while maintaining compatibility with PHP, enabling rapid development of large-scale web applications.
What are the primary use cases for Hack?
Large-scale web application development. Maintaining and modernizing PHP codebases. Developing scalable backend services. Improving code safety with static typing. Rapid iteration and prototyping in web projects
What are the strengths of Hack?
Improves reliability with static typing. Maintains compatibility with existing PHP code. Enhances code readability and maintainability. Optimized for large-scale web applications. Supports modern programming patterns
What are the limitations of Hack?
Primarily used within Facebook or HHVM ecosystems. Smaller community compared to mainstream PHP. Requires HHVM runtime, not standard PHP engine. Not ideal for small-scale or non-web projects. Learning curve for developers new to static typing
How can I practice Hack typing speed?
CodeSpeedTest offers 10+ real Hack code examples for typing practice. You can measure your WPM, track accuracy, and improve your coding speed with guided exercises.