Re: [RFC] Return Type Declarations
>
> 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?
Thread (28 messages)