DEV Community

Discussion on: On type safety without generics, and the role of package design

Collapse
 
cheshireswift profile image
☕ツ

Of course there is a small downside to this approach. Using this pattern requires two additional adapter classes and two PHP-file-specific interfaces to be written (when compared to the implementation with generics) and the delegation calls inside the adapters incur a very small runtime overhead. We consider these disadvantages negligible however when compared to the benefits of type safety and proper package dependencies.

You've expressed that the trade-off between the extra classes/overheads and type safety are worthwhile. Is the need to use extra classes to get type safety enough that you'd consider a different language (e.g. one with generics) given the option?

Collapse
 
arnoutboks profile image
Arnout Boks

For us, switching to another language is currently not an option (in terms of existing codebase, libraries and infrastructure, developer knowledge and that PHP isn't that bad). However, in a completely new context I would probably choose another language over PHP.