Ben Caradoc-Davies ha scritto: > On 15/06/10 16:17, Andrea Aime wrote: >> I still see an incompetent developer in action there. >> You look at that interface, you get a Map, so you know: >> - the API designer decided the iteration order was not important >> - the iteration order cannot be trusted > > Many other Map implementations have well-defined and lovingly crafted > iteration orders. If we re-sort every Map we get we are losing > information and duplicating effort. HashMap is the odd one out, for its > notorious bad behaviour. > >> If you still rely on a specific iteration order well, you're the cause >> of your own undoing... > > So: > (1) Alice writes a module that uses a HashMap, and exposes it as a Map. > Alice writes unit tests that make no iteration order assumptions. > (2) Bob writes a module that uses Alice's module, takes the Map, and > puts it in an ArrayList using its iteration order, and then exposes this > list. Bob writes unit tests that do not make assumptions about the order > of the items in the list.
Bob is introducting a but as it moves from a non iteration order safe container to a iteration order safe one without applying any fixed ordering. He should either use Collections.sort or explicitly state the iteration or state the list order is random in the javadocs. > (3) Carol uses Bob's module, and writes unit tests that make assertions > about the order of the list. These unit tests are likely nonportable. > > Alice could have protected her users either using LinkedHashMap or by > not exposing her HashMap. This would have been defensive programming. I would not blame Alice for Bob lack of skill (or simple oversight). She exposed a Map and made no promises on ordering, Bob took it and promised what he could not deliver. Cheers Andrea -- Andrea Aime OpenGeo - http://opengeo.org Expert service straight from the developers. ------------------------------------------------------------------------------ ThinkGeek and WIRED's GeekDad team up for the Ultimate GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the lucky parental unit. See the prize list and enter to win: http://p.sf.net/sfu/thinkgeek-promo _______________________________________________ Geotools-devel mailing list Geotools-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/geotools-devel