9 ms·
> The function returns an interface because all that should matter to you is that interface with its common behavior. I disagree. If a function wants to limit
by andrewstuart2 10y ago
> The function returns an interface because all that should matter to you is that interface with its common behavior.
I disagree. If a function wants to limit what you care about then it should return a concrete type. Interfaces exist to increase flexibility, and that includes being able to assert an implementation to gain safe access to the further structured information that underlying object contains.
> Otherwise you're just fighting the language, which doesn't make any sense, as you can just switch to Rust then.
No, using a language feature is not fighting the language. On the contrary, enforcing a pattern of increasing API surface area for functionally checking properties (i.e. the Dave Cheney error method) that would be much more cleanly accessed as structured data is fighting the language and in my opinion borders on antipattern.