[dev] Type hinting was: Constructive Criticism/Venting

Jan Schneider jan at horde.org
Fri Mar 14 12:13:42 UTC 2014


Zitat von Michael J Rubinsky <mrubinsk at horde.org>:

> Quoting Michael M Slusarz <slusarz at horde.org>:
>
>> * Type hinting is not tremendously useful, and in fact can be a  
>> hinderance.  Example: we were noticing that Horde_Imap_Client, when  
>> unserialized in IMP (which will happen on every access except  
>> logins), would recreate a cache object that would be entirely  
>> separate from the global Horde object.  To get around this, I  
>> decided to use the old wrapper trick - create a wrapper library  
>> that does nothing more than have access to the global instance when  
>> unserialized.  This can/should be accomplished without doing  
>> something like having to extend the entire Horde_Imap_Client_Cache  
>> class.  However, due to type hinting, this wasn't possible.  This  
>> calls into doubt the usefulness of type hinting.  Especially since...
>
> I agree it can be a pain and require some workarounds, but it allows  
> us to enforce a method's contract without having to add a poor-man's  
> type checking using if/typeof clauses. I guess it's a matter of  
> which trade off is more important to us.

I agree that's a trade-off, but I tend with Michael R. that enforcing  
the contract makes APIs much clearer, and coding more disciplined. The  
difficult places can often be solved by using interfaces as typehints.

-- 
Jan Schneider
The Horde Project
http://www.horde.org/
https://www.facebook.com/hordeproject



More information about the dev mailing list