What's new

Facebook dev released new programming language for HHVM

Status
Not open for further replies.
Joined
Feb 16, 2014
Posts
125
Reaction
83
Points
119
2uze0xw.jpg
What is häçk?
häçk is a programming language based on PHP just announced by Facebook. The syntax is basically the same but it adds several new features to help improving the quality of the code that you write, as well take advantage of HHVM (HipHop Virtual Machine) to execute the code faster.

What Are the Great New Features of häçk?

häçk introduced many new features relatively to the current PHP version. Some of those features were proposed to PHP over time but they were never accepted.

häçk code can be mixed with regular PHP code. The way to distinguish which code is to be processed as PHP or häçk is that PHP sections start with <?php and häçk sections start with <?hh. This allows smooth migration between PHP and häçk code, so you can take advantage of häçk features.

häçk is meant to be run with HHVM. There is a type checking phase that verifies the consistency of code according to häçk new rules.

When mixing PHP with häçk code, the PHP code sections are not checked against the new häçk rules, but regular PHP code can call häçk code and vice-versa because it is all part of the same program.

Some häçk features are for different purposes. Let me highlight some of the features that seem more important. I am grouping the features according to their purposes. Some features are meant for multiple purposes, so they are listed here in different purpose sections.

Notice that this article is being written based on häçk documentation. I wanted to try these features in practice but I was not able to compile it on OpenSuSE 13.1 Linux distribution. Any misunderstandings about the described features may be fixed later if necessary.
Bug Prevention
These are features that when used can allow that buggy code be detected before it is executed.

Type Annotations

Type annotations are like type declarations, except they are optional. If you use the wrong types of values, you will be able to detect when you make a mistake.
PHP:
<?hh
class MyClass {
  const int MyConst = 0;
  private string $x = '';
  public function increment(int $x): int {
    $y = $x + 1;
    return $y;
  }
}
Nullable Types
Nullable types is an extension of type annotations using a question mark to specify that a value maybe of a certain type or NULL.
PHP:
<?hh
function check_not_null(?int $x): int {
  if ($x === null) {
    return -1;
  } else {
    return $x;
  }
}
Collections
Collections are objects like array but their elements may be set to be of a specific type, thus allowing to detect attempts to set values to incorrect types due to application bugs.
PHP:
<?hh
// Like all objects, collections has "reference-like"
// semantics for assignment, parameter passing, and
// foreach.
function foo($v) {
  $v[1] = 7;
}
function main() {
  $v1 = Vector {1, 2, 3};
  $v2 = $v1;
  foo($v2);
  var_dump($v1);
  echo "\n";
  foreach ($v1 as $key => $value) {
    echo $key . " => " . $value . "\n";
    if ($key == 0) {
      $v1[2] = 9;
    }
  }
}
main();
häçk is definitely a somewhat unexpected and great development of PHP. It is an alternative version of PHP that provides new features that many PHP developers wanted.

---
for more info visit the following links:
official website: You do not have permission to view the full content of this post. Log in or register now.
facebook announcement: You do not have permission to view the full content of this post. Log in or register now.
info source: You do not have permission to view the full content of this post. Log in or register now.
 

Attachments

Yeah right! konting info lang ito sa mga hindi aware sa latest news. hehe. :LOL:

medyo nalito ako kung saan ba dapat ilalagay yung thread na ito feeling ko sa current news events yata ito. if wrong section. pa move nalang po. (y)
 
Status
Not open for further replies.

Similar threads

Back
Top