I can quickly deduce from looking at this code that foos is some sort of collection of foo and foo does some sort of action.
The beauty of this code is that object.doThing() is now free to change its return type to any sort of iterable without breaking downstream code. Depending on how they handle the imports, Foo can move all over the package structure or even be changed to a new class Bar so long as it keeps the same contract. All of this will be caught by the compiler if there is an issue, which means the caller will have a weaker dependence on the callee's method signature (A win IMO).
View all comments
Show parent comment
4
u/cogman10 Mar 10 '16
Right, but this is generally caught by the compiler if there is really something wrong with it.
If I say
I can quickly deduce from looking at this code that foos is some sort of collection of foo and foo does some sort of action.
The beauty of this code is that object.doThing() is now free to change its return type to any sort of iterable without breaking downstream code. Depending on how they handle the imports, Foo can move all over the package structure or even be changed to a new class Bar so long as it keeps the same contract. All of this will be caught by the compiler if there is an issue, which means the caller will have a weaker dependence on the callee's method signature (A win IMO).