Ben Caradoc-Davies ha scritto: > On 15/06/10 16:45, Andrea Aime wrote: >> 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. > > How does finger pointing between Alice and Bob help Carol? A bit of > defensive programming by Alice could have prevented Carol from being > inconvenienced.
No, no and no. Alice exposed a clear contract, it's a Map: http://java.sun.com/javase/6/docs/api/java/util/Map.html Excerpt: "The order of a map is defined as the order in which the iterators on the map's collection views return their elements. Some map implementations, like the TreeMap class, make specific guarantees as to their order; others, like the HashMap class, do not. " You expose a Map, you say there is no guaranteed iteration order. If Alice wanted to expose guaranteed iteration order she would have used a LinkedHashMap or a SortedMap. Mind Java does not even have a concept of iteration stable Map as an interface. I find this quite telling. Insisting that maps we use should be generally iteration order stable is backwards. People should just learn what a Map is. > I see HashMap iteration order leakage so often that I > suspect a systemic problem in its use. Avoiding exposing HashMap > iteration order (e.g. using LinkedHashMap) removes a common problem that > is hard to detect on a single platform. If you want to expose an interation safe map the API should say LinkedHashMap. If the API says Map instead, you have no guarantees on iteration order and you should not assume any. It's that simple. > This one bit me today when I made the unreasonable assumption that an > XSDSchema[] would be ordered: > Schemas.findSchemas (line 114) "new HashSet(": > http://svn.osgeo.org/geotools/trunk/modules/extension/xsd/xsd-core/src/main/java/org/geotools/xml/Schemas.java > That XSDSchema[] is an internal thing. Does the API state anywhere that there is a guarantee on schemas iteration order in a schema index? > > In this one, we see WFS responses in which the encoded namespace > attribute and schemaLocation order is platform-dependent, which makes > for interesting unit tests. Where does it say, in the XML schema specification, that the schema location order is important? If you have to test that, split it on spaces and newlines, and built a hashmap out of the prefix/uri array you get, and then test over it. It just requires building a utility method and can be used anywhere. That test is simply making assumption about implementation details, which is bad practice. 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