features of Hack Language

April 13, 2014

  • Type Annotations allow for PHP code to be explicitly typed on parameters, class member variables and return values:
    <?hh
    class MyClass {
      const int MyConst = 0;
      private string $x = '';
      public function increment(int $x): int {
        $y = $x + 1;
        return $y;
      }
    }
  • Generics allow classes and methods to be parameterized (i.e., a type associated when a class is instantiated or a method is called) in the same vein as statically type languages like C# and Java):
    <?hh
    class Box<T> {
      protected T $data;
    
      public function __construct(T $data) {
        $this->data = $data;
      }
    
      public function getData(): T {
        return $this->data;
      }
    }
  • Nullable Types are supported by Hack through use of the ? operator. This introduces a safer way to deal with nulls and is very useful for primitive types that don’t generally allow null as one of their values, such as bool and int (using ?bool and ?int respectively). The operator can be used on any type or class.
  • Collections enhance the experience of working with PHP arrays, by providing first class, built-in parameterized types such as Vector (an ordered, index-based list), Map (an ordered dictionary), Set (a list of unique values), and Pair (an index-based collection of exactly two elements).
  • Lambdas offer similar functionality to PHP closures, but they capture variables from the enclosing function body implicitly and are less verbose:
    <?hh
    function foo(): (function(string): string) {
      $x = 'bar';
      return $y ==> $x . $y;
    }
    function test(): void {
      $fn = foo();
      echo $fn('baz'); // barbaz
    }
Other significant features of Hack include ShapesType AliasingAsync support, and much more.

1 komen:

Blogger said...

This way my pal Wesley Virgin's tale starts with this SHOCKING AND CONTROVERSIAL video.

Wesley was in the military-and soon after leaving-he revealed hidden, "self mind control" secrets that the CIA and others used to obtain anything they want.

These are the exact same secrets many celebrities (especially those who "come out of nowhere") and the greatest business people used to become wealthy and successful.

You probably know how you only use 10% of your brain.

That's mostly because most of your brainpower is UNCONSCIOUS.

Maybe this expression has even occurred INSIDE your very own head... as it did in my good friend Wesley Virgin's head 7 years back, while riding a non-registered, trash bucket of a car without a driver's license and with $3 in his bank account.

"I'm very frustrated with going through life paycheck to paycheck! When will I finally make it?"

You've taken part in those types of conversations, ain't it so?

Your very own success story is going to be written. You need to start believing in YOURSELF.

Take Action Now!

Followers

Borak

Popular Posts