Re: Generics proposal
| From: | Etienne Kneuss | Date: | Tue, 23 Oct 2012 11:21:49 +0000 |
| Subject: | Re: Generics proposal | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-63607@lists.php.net to get a copy of this message | ||
Hi,
On Tue, Oct 23, 2012 at 4:17 AM, Levi Morrison <morrison.levi@gmail.com> wrote:
>>> Especially if the ability was afforded to arrays as well (function
>>> foo(array<Bar> $array){})...
>>
>> This would require O(n) runtime tests, I would definitely not go there.
>
> Actually, it does not require O(n) runtime tests. The solution is
> simple: store the type when it is created. Whenever an element is
> added, make sure it matches the correct type. All this does is add
> some flat overhead.
If you test every time you add one element, that's still O(n) tests
where n is the size of the array, the only benefit is that it is not
checked for each calls to a function. But now we are talking about
attaching non-trivial types to variables, and non-trivial checks in a
lot of places (think references etc..), let's not go there...
>
> I am also supportive of the idea of having generics, but I am not sure
> that the work it would take is worth it.
--
Etienne Kneuss
http://www.colder.ch