[VOTE] "Array Of" v Generics

From: Date: Fri, 24 Jan 2014 03:20:53 +0000
Subject: [VOTE] "Array Of" v Generics
Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
In recent discussions we were weighing up the options of array of and
generics came into conversation, brought forward from the Hack
language by Sara G.

I was wrong about one thing: Generics CAN have setup outside of the
type-hint, much like a collection, but it is not required. I thought
it was.

This means that array of could easily be considered "weak-generics"
and the two features can share the same syntax without confusion to
the user. A few of you said that, so sorry that I disagreed. ;)


Before we worry too much about that, the logical next question is:

Is there any interest in generics? If there is interest, then one
syntax would be preferable over the other.

With the existing proposed syntax for "array of", it looks like this:

    function(Spanner[] $spanner)

Evolving that same syntax into generics would look something like this:

    $tool = new Spanner[];
    $tool = new int[];

That would be... less than ideal, but its nice and simple for the type hints.

Using the generics syntax for... generics:

    function(array<Spanner> $spanner)
    $tool = array<Spanner>();

Obviously angle-brackets are a bit new, but that same syntax works for both.


These examples are provided to make a point, and the syntax is not
definite. The point here really is that If we care about generics,
then using generic-like syntax for this feature probably makes sense.
If we don't care about generics, then there is probably no point using
this more verbose syntax for simple "array of" type-hinting, but the
syntax could still easily change.

Can you lot vote A, B, C or D to show your interest?

A) I want Array Of, but not Generics
B) I want Generics, but not Array Of
C) I want both
D) I want neither

Nothing really binding here, its more of a survey than a vote, but it
should help with the next steps.


Thread (13 messages)

« previous php.internals (#71474) next »