I gave the RFC a few more thoughts and came to the conclusion that it
does not fit to PHP (due to the performance penalties involved).
The syntax merely hide an ugly design.
As a fan of generics I hate to say it but I'm leaning in this direction
right now as well.
Then it is still bad design compared to a collection which actually
does the check during the addition of elements.
Again, I'm agreeing here. This functionality exists right now:
interface WidgetCollection {
function addWidget(Widget $widget);
}
interface CollectionAcceptor {
function accept(WidgetCollection $wc);
}
In my opinion the additional complexity burdening the type system for this
feature outweighs the potential benefits. Are generics a nice thing? Sure.
I'd like to have them. However, I'm very uncomfortable with this RFC. Good
design means removing everything you can -- not adding everything you can.
That applies to languages just like every other form of design. Just
because we can doesn't mean we should.
The explanation from Go about why it doesn't have generics sums up my
feelings pretty well:
Generics are convenient but they come at a cost in
complexity in the type system and run-time. We haven't
yet found a design that gives value proportionate to the
complexity, although we continue to think about it.
I would think long and hard before incorporating this kind of additional
complexity going forward. I'm just not convinced right now.