[stringtemplate-interest] Map totalitarianism :o)

Terence Parr parrt at cs.usfca.edu
Sun Oct 23 13:19:43 PDT 2005


On Oct 22, 2005, at 5:50 AM, Laurent Vaucher wrote:
>   Having delved a little in the source of StringTemplate, I  
> encountered in ASTExpr.java on line 785 the method  
> isValidMapInstance(). What it does is actually prevent you from  
> using any Map implementation other than HashMap or Hashtable.  
> That's what I call totalitarianism!

The StringTemplate "supreme benevolent dictator and president for  
life" is guilty as charged! ;)

> The reason for this limitation is explained in the source :
>
>         // Special case: if it's a HashMap, Hashtable then pull using
>         // key not the property method.  Do NOT allow general Map  
> interface
>         // as people could pass in their database masquerading as a  
> Map.
>
>   As I understand it, the goal is to prevent the Model-View  
> segregation to be broken. That's laudable and fully in line with  
> the spirit of the library. But I think there are innocent  
> casualties with this scheme.

As there are with not allowing tests of attribute values like "make  
all negative numbers red".

> I'll try to explain why I think the whole Map implementation  
> control is not ' the right thing'.
>
>   First, why on earth choose HashMap and Hashtable and let TreeMap  
> out in the cold? It is a very recommendable citizen of the Map  
> community.

I forgot about that one.

>   Second, if I have built another Map implementation because I want  
> to try, let's say, a 'perfect hash' function, why should I be  
> discriminated?

That would be "collateral damage" :(

>   Finally, StringTemplate cannot make any control on get/is methods  
> and those could very easily be used as a façade to a database, so  
> the whole point of the control is lost.

Very true.

>   As a conclusion, I'd say that though intent of the control was  
> right, the way it is done isn't and the whole idea of controlling  
> what a developer might do with a library is, if not an error, a  
> utopia.

Ok, you convinced me...I'll change for 2.3; adding to bug list. :)

Thanks for your excellent analysis.

Ter


More information about the stringtemplate-interest mailing list