Re: [RFC] Return Type Declarations
| From: | Levi Morrison | Date: | Tue, 29 Apr 2014 01:30:01 +0000 |
| Subject: | Re: [RFC] Return Type Declarations | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-73838@lists.php.net to get a copy of this message | ||
>
> As far as the order of keywords in a closure, what order does Hack use?
>>
>>> The rest of the syntax seems based on it, so it seems sensible to
>>> follow
>>> suit. (I couldn't find that information from 60 seconds on hacklang.org
>>> ,
>>> but it may be there.)
>>>
>>
>>
>> At least in the 2.4 branch of HHVM (which I have installed) they put it
>> before the use statement. Now that I have thought about this more, this is
>> a poor decision:
>>
>> * use statements are basically parameters at construction time instead
>> of
>> runtime
>> * putting the return type before the use statement looks really ugly
>>
>> I will attempt to contact the HHVM team (perhaps SaraG) to see if there
>> was
>> a technical reason for it.
>>
>
> I would agree, and look forward to seeing their reasoning.
HHVM puts the return type before the use case because:
- A user is already familiar with function(): Foo
- A use statement is not really part of the function signature (during
inheritance and such)
Additionally, it is common to write closures using their shorthand
notation: ==> (see http://docs.hhvm.com/manual/en/hack.lambda.php)
I would counter:
- Use statements are special parameters (similar to constructor
arguments) and that putting it after the use statement makes more sense
- Putting it after use statements is less ugly.
- Putting it before the use statement is a bit confusing; consider this
Hack declaration:
$i = 0;
$inc = function(): Iterator<int> use(&$i) {//...
It looks like the Iterator<int> is somehow using $i.
What does this list think?