3 ms·
If you're using type signatures, the alternative is probably going to be that your program crashes at a later time. "Foo is not a Bar" is a better error message
by vertex-four 10y ago
If you're using type signatures, the alternative is probably going to be that your program crashes at a later time. "Foo is not a Bar" is a better error message than "$foo->xyz() isn't a function", and this happens much closer to the point where you've messed up.
- naranha 10y agoI disagree. I think that this type of "late type binding" is actually an advantage of dynamically typed languages. That way it does not matter if you pass a map/array/dictionary or an instance of a class as long as the properties are the same.
- chrisseaton 10y agoI think one problem is when your object quacks like a duck, but the quack doesn't mean what you think it means. Having methods that just have the right names is a pretty weak assurance, isn't it?
- zodiac 10y agoThe type hinting is optional, so if you want "late type binding" you can just omit the type hints.
- spdionis 10y ago"Fail Fast" is a pretty popular best-practice and failing immediately on a mismatched type hint is in line with that.
- vertex-four 10y agoThen... don't specify that you want a specific type?