How do you feel about type-hinting
Posted: Thu Jun 11, 2009 10:06 pm
I know some of you are hardcore type-less and others the opposite and others still, somewhere in-between. Personally I am somewhere in-between right now, and I'm always an extremist so while I am employing extensive type-hinting in my current framework, I have to constantly question myself if I am making the right move.
1. It's makes the dependencies explicit and clear so I can more accurately re-factor code later should I need to.
2. Makes static analysis and documentation a little easier
3. Makes type requirements explicit -- I know if I pass a registry to a request argument by accident (which I have done before and wondered what the bug was) type hinting will let me know and I won't be stuck wondering WTF is going on.
The negatives are of course, the explicit dependecy in a otherwise type-less language. What if someone wants to inject their own registry from framework ABC into the front controller? They would be forced into deriving from my base registry object, which isn't nessecarily a bad thing as they need to conform to my interface anyways...
I'm very strict so the more constraints I can impose on myself to ensure bug-free code the happier I usually am with the end resulting project.
1. It's makes the dependencies explicit and clear so I can more accurately re-factor code later should I need to.
2. Makes static analysis and documentation a little easier
3. Makes type requirements explicit -- I know if I pass a registry to a request argument by accident (which I have done before and wondered what the bug was) type hinting will let me know and I won't be stuck wondering WTF is going on.
The negatives are of course, the explicit dependecy in a otherwise type-less language. What if someone wants to inject their own registry from framework ABC into the front controller? They would be forced into deriving from my base registry object, which isn't nessecarily a bad thing as they need to conform to my interface anyways...
I'm very strict so the more constraints I can impose on myself to ensure bug-free code the happier I usually am with the end resulting project.