Hack (programming language)

Programming language

Not to be confused with Haxe.

Hack

Paradigms| Multi-paradigm: imperative, functional, object-oriented, procedural, reflective
Family| PHP
Designed by| Julien Verlaguet, Alok Menghrajani, Drew Paroski, others[1]
Developer| Meta Platforms
First appeared| 2014; 10 years ago (2014)
Stable release|

4.172 / 2 November 2022; 2 years ago (2 November 2022)

Typing discipline| Static, dynamic, weak, gradual
OS| Cross-platform
License| MIT[2]
Website| hacklang.org
Influenced by
PHP, OCaml, Java, C#, Scala, Haskell

Hack is a programming language for the HipHop Virtual Machine (HHVM), created by Meta (formerly Facebook) as a dialect of PHP. The language implementation is free and open-source software, licensed under an MIT License.[2][3][4]

Hack allows use of both dynamic typing and static typing. This kind of a type system is called gradual typing, which is also implemented in other programming languages such as ActionScript.[5] Hack's type system allows types to be specified for function arguments, function return values, and class properties; however, types of local variables are always inferred and cannot be specified.[3][6]

## History

[edit]

Hack was introduced on March 20, 2014.[7] Before the announcement of the new language, Facebook had already implemented the code and tested it on a large part of its web site.

## Features

[edit]

Hack is designed to interoperate seamlessly with PHP, which is a widely used open-source scripting language that has a focus on web development and can be embedded into HTML. A majority of valid PHP scripts are also valid in Hack; however, many less-often used PHP features and language constructs are unsupported in Hack.[8]

Hack extends the type hinting available in PHP 5 through the introduction of static typing, by adding new type hints (for example, for scalar types such as integer or string), as well as by extending the use of type hints (for example, for class properties or function return values). However, types of local variables cannot be specified.[6] Since Hack uses a gradual typing system, in the default mode, type annotations are not mandatory even in places they cannot be inferred; the type system will assume the author is correct and admit the code.[9] However, a "strict" mode is available which requires such annotations, and thus enforces fully sound code.[10]

## Syntax and semantics

[edit]

The basic file structure of a Hack script is similar to a PHP script with a few changes. A Hack file does not include the `<?php` opening markup tag and forbids using top-level declarations.[11] Code must be placed in an entrypoint function. These are automatically executed if they are in the top-level file, but not if the file is included via `include`, `require`, or the autoloader. Like other functions in Hack, the function names must be unique within a project – i.e., projects with multiple entrypoints can not both be called `main`:

<<__EntryPoint>>
function main(): void {
echo 'Hello, World!';

The above script, similar to PHP, will be executed and the following output is sent to the browser:

Hello, World!

Unlike PHP, Hack and HTML code do not mix; either XHP or another template engine needs to be used.[8]

### Functions

[edit]

Like PHP 7, Hack allows types to be specified for function arguments and function return values. Functions in Hack are thus annotated with types like the following:

// Hack functions are annotated with types.
function negate(bool $x): bool {
return !$x;

## See also

[edit]

* Computer programming portal

* Phalanger

## References

[edit]

1. ^ O'Sullivan, Bryan (2014-03-28). "Where Credit Belongs for Hack". Archived from the original on 2021-03-01. Retrieved 2019-02-06.
2. ^ a b "facebook/hhvm: hhvm, hphp, hack, License". GitHub.com. Meta Platforms. 2018-04-11. Archived from the original on 2019-01-07. Retrieved 2019-02-06.
3. ^ a b Lockhart, Josh (2014-04-03). "Facebook's Hack, HHVM, and the future of PHP". O'Reilly Media. Archived from the original on 2019-01-07. Retrieved 2019-02-06.
4. ^ Cade Metz (2014-03-20). "Facebook Introduces 'Hack,' the Programming Language of the Future". Wired. Archived from the original on 2014-03-28. Retrieved 2019-02-06.
5. ^ Aseem Rastogi; Avik Chaudhuri; Basil Hosmer (January 2012). "The Ins and Outs of Gradual Type Inference" (PDF). Association for Computing Machinery (ACM). Archived (PDF) from the original on 2017-08-12. Retrieved 2019-02-06.
6. ^ a b "Hack Manual: Hack and HHVM – Type Annotations". docs.hhvm.com. Archived from the original on 2018-08-02. Retrieved 2019-02-06.
7. ^ Verlaguet, Julien; Menghrajani, GANDHI (2014-03-20). "Hack: a new programming language for HHVM". Facebook. Archived from the original on 2019-02-09. Retrieved 2019-02-06.
8. ^ a b "Inconsistencies: Introduction". docs.hhvm.com. Archived from the original on 2019-04-04. Retrieved 2019-04-04.
9. ^ "Hack Manual: Partial Mode". docs.hhvm.com. Archived from the original on 2018-11-19. Retrieved 2019-02-06.
10. ^ "Hack Manual: Strict Mode". docs.hhvm.com. Archived from the original on 2018-11-19. Retrieved 2019-02-06.
11. ^ Emmott, Fred (2019-02-11). "HHVM 4.0.0". hhvm.com. Archived from the original on 2021-05-14. Retrieved 2019-05-02.

## External links

[edit]

* Official website and language reference
* Facebook Q&A: Hack brings static typing to PHP world
* A tutorial on converting an existing PHP project to Hack
* KPHP: An Executable Formal Semantics for PHP

* v
* t
* e

PHP

People|

* Andi Gutmans
* Rasmus Lerdorf
* Zeev Suraski

Resources|

* Accelerator (List)
* Composer
* Editors
* Libraries
* PEAR

Implementations|

* HHVM
* HPHPc
* Parrot
* PeachPie
* Phalanger
* Quercus
* Zend Engine

Web frameworks|

* CakePHP
* CodeIgniter
* Drupal
* eZ Publish
* Fat-Free
* Flow
* FuelPHP
* Grav
* Gyroscope
* Horde
* Joomla!
* Laminas
* Laravel
* li₃
* Midgard
* MODX
* Nette
* Phalcon
* PHP-Fusion
* PHP-Nuke
* Pop PHP
* PRADO
* ProcessWire
* Qcodo
* Silverstripe
* Symfony
* TYPO3
* WordPress
* XOOPS
* Yii

Testing|

* Behat
* PHPUnit

ORMs|

* Doctrine

IDEs|

* Aptana
* Codelobster
* Eclipse PDT
* NetBeans
* PHPEdit
* PhpStorm
* Zend Studio

Widget toolkit|

* PHP-GTK
* wxPHP

* Category
* Commons

* v
* t
* e

Meta Platforms

Products
and services|

| Facebook|

* Service
* Features
* Beacon
* Bluetooth Beacon
* Credits
* Dating
* EdgeRank
* Feed
* Gaming
* Graph Search
* Instant Articles
* Like button
* Live
* Lookalike audience
* Onion address
* Platform
* Connect
* Safety Check
* Stories
* Watch
* list of original programs
* Zero

|

Instagram|

* Hyperlapse
* IGTV
* List of most-followed accounts
* List of most-liked pictures
* Threads

Hardware|

* Portal
* Meta Quest
* Quest 1
* Quest 2
* Quest 3
* Pro
* Touch
* Ray-Ban Stories

Other|

* Express Wi-Fi
* Free Basics
* Messenger
* Kids
* Rooms
* Mapillary
* Meta AI
* Meta Horizon OS
* Supernatural
* WhatsApp
* Workplace

Former|

* Atlas Solutions
* FriendFeed
* Giphy
* Home
* HTC First
* M
* Oculus Go
* Oculus Rift
* CV1
* S
* Onavo
* Paper
* Slingshot
* tbh
* Wirehog

People|

| Founders|

* Mark Zuckerberg (28% equity)
* Dustin Moskovitz (7%)
* Eduardo Saverin (5%, formerly)
* Chris Hughes (1%, formerly)
* Andrew McCollum

|

Board|

| Current|

* Mark Zuckerberg
* Marc Andreessen
* John D. Arnold
* Drew Houston
* Nancy Killefer
* Robert M. Kimmitt
* Hock Tan
* Tony Xu

|

Former|

* Sheryl Sandberg
* Peter Thiel

Executive
officers|

| Current|

* Mark Zuckerberg (Chairman and CEO)
* Javier Olivan (COO)
* Andrew Bosworth (CTO)
* Chris Cox (CPO)
* Nick Clegg (President of Global Affairs)
* Jennifer Newstead (Chief Legal Officer)

|

Former|

* Sean Parker (4%, formerly)
* Owen Van Natta
* Gideon Yu
* Adam D'Angelo
* Chris Kelly
* Bret Taylor
* Sheryl Sandberg
* Mike Schroepfer
* David Wehner
* David Ebersman
* Marne Levine
* Alex Stamos

Oversight
Board|

| Members|

* Catalina Botero Marino, Co-Chair (2020–)
* Jamal Greene, Co-Chair (2020–)
* Michael W. McConnell, Co-Chair (2020–)
* Helle Thorning-Schmidt, Co-Chair (2020–)
* Afia Asantewaa Asare-Kyei (2020–)
* Evelyn Aswad (2020–)
* Endy Bayuni (2020–)
* Katherine Chen (2020–)
* Nighat Dad (2020–)
* Tawakkol Karman (2020–)
* Maina Kiai (2020–)
* Sudhir Krishnaswamy (2020–)
* Ronaldo Lemos (2020–)
* Julie Owono (2020–)
* Emi Palmor (2020–)
* Alan Rusbridger (2020–)
* András Sajó (2020–)
* John Samples (2020–)
* Nicolas Suzor (2020–)
* Suzanne Nossel (2021–)
* Khaled Mansour (2022–)
* Pamela San Martin (2022–)
* Paolo Carozza (2022–)
* Kenji Yoshino (2023–)

|

Board of
Trustees|

* Stephen Neal, Chair (2021–)
* Kristina Arriaga (2020–)
* Cherine Chalaby (2020–)
* Wanda Felton (2020–)
* Kate O'Regan (2020–)
* Robert Post (2020–)

Former
members|

* Pamela S. Karlan (Board Member, 2020–2021)
* Paul G. Haaga Jr. (Board of Trustees Chair, 2020–2021)

Notable
employees|

| Current|

* Lars Rasmussen (Graph Search director)
* Naomi Gleit (VP of social good)
* Nicola Mendelsohn (head of Global Business Group)
* Adam Mosseri (head of Instagram)
* Thomas Reardon (Reality Labs director)

|

Former|

* Blake Ross (Director of Product)
* Ted Ullyot (VP, General Counsel, and Secretary)
* Hugo Barra (VP of Reality Labs)
* John Carmack (CTO of Reality Labs)
* Matt Cohler
* Charlie Cheever
* Randi Zuckerberg
* Yishan Wong
* George Hotz
* Joe Lockhart
* Andrei Alexandrescu (research scientist)
* Chamath Palihapitiya (VP of User Growth)
* Elliot Schrage (VP of Global Communications, Marketing and Public Policy)
* Frances Haugen (Product Manager of Civic Integrity Team)

Open source|

* Apache Cassandra
* Apache Hive
* Apache Thrift
* Buck
* FQL
* Hack
* HHVM
* HipHop for PHP
* Infer
* MyRocks
* Open Compute Project
* Phabricator
* React
* React Native
* RocksDB
* Scribe
* Telecom Infra Project
* Tornado

Mass media|

* The Facebook Effect
* The Accidental Billionaires
* The Social Network

Concepts|

* Activity stream
* Social graph
* Friending and following
* Reblogging
* Fan-gating
* Facebook diplomacy
* Facebook like button

Business|

* History of Facebook
* Timeline of Instagram
* Timeline of WhatsApp
* Acquisitions
* f8 conference
* IPO
* Censorship
* Criticism
* Cambridge Analytica data scandal
* 2020 ad boycotts
* 2021 company files leak
* Privacy
* Content management
* Litigation
* Young v. Facebook, Inc. (2011)
* Fraley v. Facebook, Inc. (2016)
* Force v. Facebook, Inc. (2019)
* Facebook, Inc. v. Duguid (2021)
* Federal Trade Commission v. Meta Platforms, Inc. (ongoing)
* unionization

Lists|

* Most-followed Facebook pages

Related|

* Priscilla Chan (wife of Mark Zuckerberg)
* Chan Zuckerberg Initiative
* Aquila Internet relay drone
* Willow Village
* WaveGroup Sound
* 2021 Facebook outage

* v
* t
* e

Programming languages

* Comparison
* Timeline
* History

* Ada
* ALGOL
* Simula
* APL
* Assembly
* BASIC
* Visual Basic
* classic
* .NET
* C
* C++
* C#
* COBOL
* Erlang
* Forth
* Fortran
* Go
* Haskell
* Java
* JavaScript
* Julia
* Kotlin
* Lisp
* Lua
* MATLAB
* ML
* Pascal
* Object Pascal
* Perl
* PHP
* Prolog
* Python
* R
* Ruby
* Rust
* SQL
* Scratch
* Shell
* Smalltalk
* Swift
* more...

* Lists: Alphabetical
* Categorical
* Generational
* Non-English-based
* Category

*[v]: View this template
*[t]: Discuss this template
*[e]: Edit this template