On 01/19/2014 10:02 PM, Sara Golemon wrote:
However, I have but one little issue with the HHVM syntax. Why is the ?
before the type name? I much prefer the C#-style Bar? to this confusing
?Bar. I suppose this is only a minor issue, though.
Two reasons come to mind, both essentially aesthetic:
* Symbol crowding: function foo(array? &$bar) { }
bar by ref expects array, but may take null (which is perfectly common
for a by-ref variable). Trouble is, '? &$' is starting to look
perlish.
* Generic expansion:
Prefix: function foo(?array<Bar<?int>> $baz)...
Suffix: function foo(array<Bar<int?>>? $bar)...
Both proclaim a nullable array of non-nullable Bar objects of nullable
type int. The prefix version makes it much more obvious which '?'
goes with which portion of the type structure.
function foo(array?<Bar<int?>> $baz)... sounds tempting, but some
shift/reduce conflicts start to emerge out of that stacking of tokens.
Resolvable, of course, but complicating the parser rules over a bit
of aesthetics like that.... You can't see it, but I've got my frownie
face on right now.
-Sara
P.S. - I'm not voting for or against anything at this point either.
Just offering input during discussion phase, as we're all meant to. :)
Sara,
In the original internals thread about generics, you mention that the HHVM team were going to donate their effort and patch to PHP so we could have generics in PHP .... so ... how did that work out, is there a patch (even a half finished one) ??
I'm a bit disappointed that this has been turned into a conversation about something I see as completely different.
I wasn't looking to introduce a paradigm, and think it would be quite terrible to use the syntax for generics for this; I only want to hint for generics when I can program with generics, and even if I wrote the patch next week, the original conversation made it seem like it would never be merged anyway ...
Was there some technical difficulty that stopped the work on generics when it was first brought up, or did you just realise that it would never get through ??
Original conversation about generics:
http://php.markmail.org/message/fhqgkzyui3cpantg?q=net%2Ephp%2Elists%2Einternals+generics+order:relevance&page=1
Cheers
Joe