On 16/01/14 20:14, Andrey Andreev wrote:
Am I the only one who finds both proposed syntaxes somewhat confusing?
The originally proposed 'Bar[]' simply looks strange.
It is, however, familiar to C, C++, C# and Java users.
So, how about this:
Array[Bar] $a - $a is array containing only instances of Bar
Array[Bar|null] $a - $a is array containing Bar instances or nulls
Array[Bar] $a = null - $a is either null or array containing only
instances of Bar
Array[Bar|null] $a = null - above, but the array can contain nulls
That doesn't make much sense as a syntax, IMO. It looks like "Bar" is the index of the Array here. Surely it could use angle brackets, which would be familiar to people who've dealt with generics (C++, C#, Java users):
Array<Bar> $a
It's easily readable and everybody should be able to recognize what this
thing does even without prior knowledge.
It's not clear to me at all at first glance. Is that a Bar-indexed array?
Or even (at a later stage):
Array[]["key1", "key2"]
... which would hint for a numeric index array containing associative
arrays that in turn must have the defined keys. This is indeed a bit crazy,
but possible to add in the future without BC breaks. You could even shove
scalar typehints in there as soon as they are implemented.
...that's even less intuitive to me.
--
Andrea Faulds
http://ajf.me/