Re: what is encapsulation in an interface ?
Ken Wesson wrote:
You need less detailed knowledge of the API library to know what it
Any argument that justifies by promoting ignorance of the API is thereby
fatally flawed.
Other than that, the discussion seems to be a matter of style. It is
certainly plausible that the library method would have better performance than
the hand-written 'for' loop, as the java[x].* APIs have the benefit of close
cooperation with the JVM implementation, so an argument based on performance
is a no-go.
Clarity of "intent" is a specious argument, akin to debating how many angels
can dance on the head of a pin. We can and should presume that "any Java
novice who has gotten past the for-loop chapter of his Java 101 textbook"
would be familiar with the collections API and with 'for' loops, so that
washes out. (Any self-described "Java programmer" who does not /at least/
work to keep up to date /at least/ with the collections API is a saboteur, a
bounder, a poseur and a thief.)
The API approach is less likely to have bugs, generally, than the hand-written
loop approach. That alone justifies it. In the real-world example of a
production system employing professional-pay-grade developers that I cited
earlier, the 'for' loop was complex and bug-ridden. My colleague's rewrite
using 'Set#retainAll()' was bug-free and easy to confirm that it was so. If
'for' loops were equivalently reliable, how did that happen?
--
Lew
Ceci n'est pas une pipe.