[stringtemplate-interest] ST, Django and get_something_display()

Terence Parr parrt at cs.usfca.edu
Wed Aug 13 14:53:24 PDT 2008


On Aug 1, 2008, at 1:32 AM, Roman Odaisky wrote:

> On Friday, 01.08.2008 01:27:39 Terence Parr wrote:
>
>> Hi Roman, i assumed people would follow the javabeans notation of
>> getFooDisplay.  Too bad django doesn't. hmm...well, I'd say create a
>> wrapper object that converts syntax...register a renderer like
>> djangoToBeans object that answers getFooDisplay and delegates to
>> django object.  Might be Able to use reflection or something to make
>> this more automatic...
>
> Hi,
>
> I guess the intent was only to allow calling methods which don’t  
> modify the
> object?

Yep, must be side-effect free.

> What about modifying the logic a bit: for $o.m$ if m is a method of  
> o, and
> either m starts with /[gG]et[A-Z]/, or /get_/, or it has a special  
> attribute,
> for example, StringTemplate_safe, then call o.m(), otherwise use the  
> old
> rules?

Adding 'get_' Would be okay but there could be many of the patterns.

> All the languages which run StringTemplate have made a wise decision
> of supporting reflection and attributes (and the stupid decision of  
> ignoring
> const, which would have been the ideal solution for this), so  
> something like
> this seems easily implementable and it no longer imposes a certain  
> naming
> convention. (I won inder whether the .NET version uses get or Get  
> prefix.)

Hmm... well, i suppose I could add a feature that it looks for a  
method with that exact name.. Right now it looks for a get method.  
failing that it looks for a field. failing that, I could make it look  
for that generic method. the problem is that it is now able to call a  
random method on the object, which is against the principle of  
enforcing (as well as possible) model-view separation.

> For example, those following the Qt style don’t use the get prefix  
> at all
> (o.someProperty()/o.setSomeProperty()), those using the Apps Hungarian
> notation also don’t need it (the Hungarian prefix indicates quite  
> clearly
> that a method is a getter).

Yeah, each target implementation language should use with the local  
language uses. Java always uses get/set.

> So what about adding an attribute which would indicate safe methods?

Hmm...a possibility.  anybody else have an opinion?

Ter


More information about the stringtemplate-interest mailing list