Hello World in Hack

Published on 07 May 2019 (Updated: 23 August 2023)

Welcome to the Hello World in Hack page! Here, you'll find the source code for this program as well as a description of how the program works.

Current Solution

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

Hello World in Hack was written by:

This article was written by:

If you see anything you'd like to change or update, please consider contributing.

How to Implement the Solution

At long last, let's take a stab at Hello World in Hack.

Although Hack is derived from PHP, this code looks quite different than PHP. The first thing you'll notice is this:

<<__EntryPoint>>

The <<...>> is how Hack defines an attribute. The __EntryPoint attribute defines a top-level function where execution is started. That function is main, but it does not have to be called main. Any function with the __EntryPoint attribute will be considered the top-level function.

Next, the main function is defined. For this sample program, there are no command-line arguments to process, so no arguments are needed. The function does not return anything, so the return type is void.

Finally, there is the echo statement, which is exactly the same as Hello World in PHP. However, I will point out that you can't mix HTML with Hack like you can with PHP, so that's one of the biggest syntactic differences. Otherwise, both languages perform a similar function: backend web development.

How to Run the Solution

If we want to try this code, we can use an online Hack compiler.

Alternatively, we can download the Hack Virtual Machine to run Hack code locally. From there, I recommend reading up on how to get started with Hack. Getting everything up and running is bit out of scope of this article.