FACEBOOK HACK

 
FACEBOOK HACK

Facebook just released a new programming language, HACK – a language based on PHP that introduces several great enhancements

It allows programmers to write code faster while more easily avoiding errors.

INTRO OF HACK

Hack is a programming language based on PHP. The syntax is basically same as PHP. It improves the quality of the code and take the advantage of HHVM (HipHop Virtual Machine) to execute the code faster.

What’s New in HACK

Hack code can be mixed with regular PHP code. It can be distinguised by with the start tag <?php for PHP and <?hh for HACK.

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

Sample code:

<?hh
class Sample {
const int pi = 3.14;
private string $a = ”;
public function increment(int $a): int {
$b = $a + 1;
return $b;
}
}

Type Annotations

When using type annotations you are telling the runtime engine that a value is of a specific type, so it can optimize the generated native machine code to treat values of that type and avoid spending CPU time performing needless type conversions.

Collections

Given that collections can hold values of the same type

Asynchronous Programming

Asynchronous programming allows a script to start multiple tasks that run in parallel. Those tasks are often I/O operations that rely on operations that are run by separate servers or other OS processes like those that perform file access, network access and database access.

Traditionally PHP executes those tasks and waits for them to finish before it returns the control to your script. This is synchronous programming.

Synchronous programming is often a waste of performance because your script could start multiple I/O tasks and have them run in parallel, so the end result of all those tasks would returned faster.

With synchronous programming each task can only be started after the previous task has finished. Imagine a script that collects information from different sites. Each one will hold your script for as much as the servers take to respond.

PHP has limited support for asynchronous programming for some purposes.

Hack made asynchronous programming can be done cleanly.

Hack introduces the await and async keywords to define code that may be executed in parallel. The really good part is that you can use a await statement to suspend the execution of the code that follows that statement until the contained asynchronous code finishes.

This is a very elegant asynchronous programming solution because you do not have to be concerned with callbacks or internal event loops, to make your script hold in a certain position while parallel tasks keep running and do other things.

Code Reusability

Generics are basically code templates. This allows to create different classes that perform the same operations using the same code on classes of different types.

I reviewed some of the features in HACK.. HACK may include more features incrementally…

Lakshmi Priya
Latest posts by Lakshmi Priya (see all)