Introduction to Hack programming

Source: Internet
Author: User
Tags hhvm

Original link: http://www.hacklang.org.cn/



<?HH of civil service network in hack programming language
echo "Hello, hacklang.org.cn!";
?>

Neat! Safety! Can be refactored! Compatible php!
Hack is a programming language introduced by Facebook, used in HHVM. For HH, you can use hhlang.org.cn to access this site.

Novice Tutorial HHVM Installation 1

<?hh
2
Class MyClass {
3
  Public Function alpha (): int {
4
    return 1;
5
  }
6
7
  Public Function Beta (): string {
8
    Return ' Hi Test ';
9
  }
10
}
11
12
function f (MyClass $my _inst): string {
13
  Fix me!
14
  return $my _inst->alpha ();
15
}
What is the Hack programming language

Hack is a programming language used in HHVM, which can be combined with PHP to operate seamlessly with each other. Hack implements a PHP-style fast development cycle that provides static typing while adding many features that are common in other modern programming languages.

Hack provides instantaneous type checking through the local server monitor file system. It typically runs in less than 200 milliseconds, so it's easy to integrate into your development workflow without introducing significant latency.

Hack's goal is to provide developers with a way to write clean, secure, and reconfigurable code, while maintaining a certain degree of compatibility with the current PHP code base. The main way to achieve this is to provide a way for developers to examine the type information of PHP functions and classes, thus providing a type-checking tool. In addition, a specific language feature is provided: The type callout feature will allow PHP code to annotate parameters, class member variables, and return value types. (The original PHP is not sensitive to the type of the parameter.) such as String type and shaping. )

<?HH
class MyClass {
  const int myconst = 0;
  private string $x = ';
  Public function increment (int $x): int {
    $y = $x + 1;
    return $y;
  }
Generics, PHP (in the same static type language such as C language, Java, C #). Generics allow classes and methods to be parameterized (that is, when a class is instantiated or a method call is associated with a type). Here's an example:
<?HH
class Box<t> {
  protected T $data;

  Public function __construct (T $data) {
    $this->data = $data;
  }

  Public Function GetData (): T {return
    $this->data;
  }
}
Nullable Types Hack adds a more secure way of handling null values through the idea of what is known as "nullable" (sometimes referred to as "possible" or "option"). Nullable values allow null values to be allocated and check for any type on them. Nullable values are primitive types typically do not allow nulls as their values, such as bool and int, but they can also be user-defined classes. Here is an example. Attention. Operator is used to indicate nullable. Hack adds the container type and interface to PHP. Built on Hack support for generics, Hack adds built-in parameterized sets, such as vectors and maps. Collections are dedicated to data storage and retrieval. The collection implements many of the same interfaces and expands to create more specialized collections. Currently, Hack can implement the following specific collection types: lambda expression offer similar functionality to PHP closures, but they-capture variables from the enclosing f Unction body implicitly and are less verbose:
<?hh
function foo (): (Function (String): string) {
  $x = ' bar ';
  Return $y ==> $x. $y;
}
function test (): void {
  $FN = foo ();
  Echo $fn (' Baz '); Barbaz
}

More features of the hack language include Shapes, Type aliasing, Async support, and more.

You can use it on your own code base, with many open source hack and their conversion tools available. We will continue on the road ahead: look forward to your feedback, but also welcome you to participate in the HHVM and hack family.
Of course there are many other features that can be read in the official detail.

[Project official website]: http://www.hacklang.org.cn/
[Download address]: http://www.hhvm.org.cn/install.php
[Help document]: http://www.hacklang.org.cn/cookbook.php
[License Agreement]: GNU general public License (GPL)
QQ Group 2,181,271,862 Dimension Code
Community resources Navigation Hacklang microblogging HHVM IRC Chat hack programming language Example HHVM open source information GitHub License contributing cookbook on GitHub Docs on GitHub

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.