Hack 语言学习/参考---1.2 Hack Background

原文链接:http://www.cnblogs.com/Jack8Chen/p/3620895.html

Hack Background

Facebook was initially built with PHP. Parameters and return types were specified in comments. Parsers could use this to create documentation. But type-checking was non existent.

<?php
/**
 * Wraps a name in a box
 *
 * @param raw-str $name
 * @return html-str
 */
function say_hello($name) {
  return "<div class=\"box\"<hello ".htmlize($name)."</div>";
}

 

In 2009, a PHP compiler called HipHop was released. In 2010, minor changes to the PHP language were introduced by the HPHP team to improve development time and provide basic type safety. The changes were XHP and parameter type constraints.

<?php
/**
 * Wraps a name in a box
 *
 * @return xhp
 */
function say_hello(string $name) {
  return <div class="box"<Hello {$name}>/div>;
}

 

In 2012, Facebook engineering teams started exploring the idea of annotating return types. And the Hack language was born...

转载于:https://www.cnblogs.com/Jack8Chen/p/3620895.html

上一篇:空操作 空模块处理


下一篇:史上最全的CSS hack方式一览