3 ms·
I haven't looked this over too much but I'm curious as to why they did this: <?hh class MyClass { const int MyConst = 0; private string $x = ''; public fu
by wambotron 13y ago
I haven't looked this over too much but I'm curious as to why they did this:
<?hh
class MyClass {
const int MyConst = 0;
private string $x = '';
public function increment(int $x): int {
$y = $x + 1;
return $y;
}
}
instead of this:
<?hh
class MyClass {
const MyConst: int = 0;
private $x: string = '';
public function increment(int $x): int {
$y = $x + 1;
return $y;
}
}
The first seems inconsistent to me. Especially coming from AS3/Haxe where the function return value is indicated in the same manner.
- jdp 13y agoWould be more consistent to suffix the types in function decls as well, e.g. `increment($x: int)` vs. `increment(int $x)`.
- wambotron 13y agoYep. So much weirdness here when they had a really good shot at "fixing" it.
- elgenie 13y ago(I work on Hack at FB) function f(int $x): float { ... } For property and constant declarations, we chose to be consistent with the parameter typehint syntax (int $x) instead of the function return type annotation (float). A nice effect of this decision is that this allows us to change: class C { private int $x = 20; public function __construct(int $x,) { $this->x = $x; } } into the shorter and cleaner: class C { public function __construct( private int $x = 20, ) {} }