[stringtemplate-interest] Iterating over a map
parrt at cs.usfca.edu
Tue May 3 16:11:51 PDT 2005
On May 3, 2005, at 2:48 PM, Tom Bentley wrote:
>> Hi Tom. Yeah, that's why i was thinking we'd need that temp object.
>> I don't like having to assume something is a map, but i already break
>> this rule by allowing object.property ;)
> Yeah, I saw the special case code in there, worrying about Hashtables
> and the like.
> There are quite a few 'safe' (without side-effects) implementations of
> Map in J2SE to worry about; Hashtable, HashMap, TreeMap,
> LinkedHashMap, possibly IdentityHashMap (though that's something of a
> special case). IMHO, supporting the TreeMap and LinkedHashMap is
> reasonably important, since it gives some sort of control over
> iteration order.
> On the other hand, it seems a shame that people have to shoehorn their
> model into a HashMap/Hashtable: Fundementally, you can't know for sure
> that the getters people write (and StringTemplate merrily calls) don't
> have weird side-effects, so part of me says just to assume the Map
> interface regardless: If people write a Map whose get() has
> side-effects that's their look-out.
Yeah, i've fought myself over this for a long time. I really like to
prevent the side-effects, but I've already allowed the hole with
.getProperty() as you say. Hmm...you may have convinced me. Though,
$db.bob$ is way more tempting to use as a database. It's actually
worse than getproperty as you can pass a parameter in, which is mucho
CS Professor & Grad Director, University of San Francisco
Creator, ANTLR Parser Generator, http://www.antlr.org
More information about the stringtemplate-interest