[stringtemplate-interest] Map totalitarianism :o)

Laurent Vaucher blo.b at infonie.fr
Sat Oct 22 05:50:54 PDT 2005


   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 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. 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.
   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?
   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.

   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.


Laurent.



More information about the stringtemplate-interest mailing list