Hack 是 Facebook 推出的一款新的编程语言。
Hack 是由Facebook开发的,同时结合了动态类型语言(如C语言)和静态类型语言(如PHP语言)两种特点的一种编程语言。通常在使用静态类型语言编程 时,开发者会在程序被运行前就知道错误发生的位置。而在更为当前的编程环境里,动态类型语言会一直运行到直至程序出错崩溃。
特性:
- 该语言将能使代码的编写和测试更加高效快速,能够在程序运行前捕获到其中的错误;
- 同时结合了动态类型语言(如PHP语言)和静态类型语言(如C语言)两种特点;
- Hack对代码本身的运行速度并没有实质影响;
- 基于hhvm(hiphop vm)运行
我不知道我的系统环境如何,用下面的步骤就装好了
hhvm --version
HipHop VM 2.5.0-dev+2014.03.20 (rel)
Compiler: heads/master-0-gc4b6a793b0d6bc28e63c29151ca0a5c12bbbf856
Repo schema: 0e601f9f2c514001cbe38f215a281d34f36a9a9c
Installing Boost 1.49
Similarly, HHVM requires Boost 1.49, but Ubuntu 12.04 only ships with 1.48. To get a more recent version, follow these steps:
sudo add-apt-repository ppa:mapnik/boost
sudo apt-get update
sudo apt-get install libboost1.49-dev libboost-regex1.49-dev \
libboost-system1.49-dev libboost-program-options1.49-dev \
libboost-filesystem1.49-dev libboost-thread1.49-dev
For Ubuntu 12.04:
wget -O - http://dl.hhvm.com/conf/hhvm.gpg.key | sudo apt-key add -
echo deb http://dl.hhvm.com/ubuntu precise main | sudo tee /etc/apt/sources.list.d/hhvm.list
sudo apt-get update
sudo apt-get install hhvm-nightly
装好后,创建一个文件如 first.hack,代码如下:
<?hh
// Hack functions are annotated with types.
function my_negation(bool $x): bool {
return !$x;
}
// FIXME: annotate this function parameter
// and return with the type 'int'.
function add_one(int $x): int {
return $x+1;
}
echo add_one(5);
在命令行运行
hhvm first.hack
安装指南
1. https://github.com/facebook/hhvm/wiki/Building-and-installing-HHVM-on-Ubuntu-12.04