r/programming • • Mar 20 '14

Facebook introduces Hack: a new programming language for HHVM

https://code.facebook.com/posts/264544830379293/hack-a-new-programming-language-for-hhvm/
802 Upvotes

526 comments sorted by

View all comments

-2

u/[deleted] Mar 20 '14

Awesome. These are some things I wish the official PHP would adopt. I just wish FB wasn't developing this.

Some criticisms:

  • Why are types specified with the same syntax other languages use for extension?

Their example

public function increment(int $x): int
{
    $y = $x + 1;
    return $y;
}

I'd rather see

public int increment(int $x)
{
    $y = $x + 1;
    return $y;
}

which also happens to fall inline with their "less verbose" goal. Also, can you use arbitrary types here? If I have a class MyType, can I do this?

public function foo() : MyType
{
    return new MyType();
}
  • Why in god's name are nullable types specified with ?bool instead of bool?? Do any other languages put the question mark first? Was the concern that it would be confused with Ruby's something.valid?? There's no examples of this [Ruby's way] in PHP or HACK that I'm aware of.

  • The lambda syntax. Come on. FB, you invented a totally unfamiliar syntax for this, and it's totally verbose. I have to specify a method name, and then the method signature, and then the return type for the method signature, and then what the heck is ==>? The "identity greater than" operator? Is this yielding a value!? What is it!?

Make the syntax sane:

var $xPlusOne = int $x => $x + 1;

or, to rewrite the example provided:

void test()
{
    $y = 'baz';

    echo string $x => {
        $x . $y;
    }
}

http://msdn.microsoft.com/en-us/library/bb311046.aspx

http://www.secnetix.de/olli/Python/lambda_functions.hawk

5

u/Nomikos Mar 20 '14

The lambda syntax. Come on. FB, you invented a totally unfamiliar syntax for this, and it's totally verbose.

The first example seems silly, but if you don't need a function that returns a function they're rather compact: http://hacklang.org/manual/en/hack.lambda.examples.php

and then what the heck is ==>?

Aliens!

3

u/[deleted] Mar 20 '14

Ah, okay. So their lambda syntax is sane, but it's the closure syntax I'm complaining about. Thanks for clarifying what ==> is.

Now I wish they co-opted ->. ==> looks too much like a comparison operator to me (not that => doesn't).

0

u/[deleted] Mar 21 '14

It looks like a god damn arrow, jesus christ why are you typing so much when all you really mean to say is "I'm a shit programmer who has never seen lambdas before) holy fuck.

→ More replies (3)