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