You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by John McNally <jo...@clearink.com> on 2000/11/10 02:30:48 UTC

introspection

Was there a decision against allowing methods with empty arguments to be
specified without the ()? 

Example.

$browser.isJavaScriptOK

as opposed to 

$browser.isJavaScriptOK()

It obviously wouldn't be too hard to add the first form, is anyone
opposed?

The backend programmer could fudge it with a getisJavaScript() method,
but the isXXX format for boolean properties, is pretty standard.  And I
don't see any reason why the empty () pair should be required.

Also,
would there be much benefit in trying to cache the "correct"
interpretation of a ASTIdentifier?  It would seem to me that the
interpretation will not change in most circumstances. So if out of
1.  getisOK()
2.  get("isOK") or get(isOK)
3.  isOK()

#3 is correct, it would be good to check it first the next time the
template is used.
Thoughts?

John McNally

Re: introspection

Posted by "Daniel L. Rall" <dl...@finemaltcoding.com>.
John McNally wrote:
> 
> Jason van Zyl wrote:
> >
> > On Thu, 9 Nov 2000, John McNally wrote:
> >
> > > Was there a decision against allowing methods with empty arguments to be
> > > specified without the ()?
> > >
> > > Example.
> > >
> > > $browser.isJavaScriptOK
> > >
> > > as opposed to
> > >
> > > $browser.isJavaScriptOK()
> > >
> > > It obviously wouldn't be too hard to add the first form, is anyone
> > > opposed?
> >
> > As a standard boolean property I think it should be supported
> > in the #if directive. So if you have the following:
> >
> > #if ($user.LoggedIn)
> 
> But wouldn't it be easier and more flexible to support the dropping of
> empty () in general?  Why does Velocity not allow this when it was
> something that could be done in WM?  I am thinking it is only a couple
> of lines of code in ASTIdentifier, am I wrong?
> 
> Dropping the "is" would also be worthwhile, but then it also might be
> good to check the "has" prefix as well.  I don't know if "has" in
> allowed in beans, but it is in wide use.

I'm in agreement with John that bean-like introspection needs to be
supported (eventually, at least).
-- 

Daniel Rall <dl...@finemaltcoding.com>

Re: introspection

Posted by Jason van Zyl <jv...@periapt.com>.
On Fri, 10 Nov 2000, John McNally wrote:

> But wouldn't it be easier and more flexible to support the dropping of
> empty () in general?  Why does Velocity not allow this when it was
> something that could be done in WM?  

I would like to stick to standard bean behavior for properties.
If there is no () on the end then it is expected to be a property
as per the bean spec. I didn't really look a whole lot at WM :-)
But we can certainly add it if people want it that way.

> I am thinking it is only a couple
> of lines of code in ASTIdentifier, am I wrong?

It would be easy enough to add, yes.

> Dropping the "is" would also be worthwhile, but then it also might be
> good to check the "has" prefix as well.  I don't know if "has" in
> allowed in beans, but it is in wide use.

$gunslinger.TriggerFinger would not translate
into $gunslinger.hasTriggerFinger() as per the bean spec.

> > All results of introspection are cached after the first pass. Not
> > only for properties but for all methods as well. The results
> > of introspection are actually held in the AST itself in the
> > pertinent nodes.
> 
> I guess I need to update my checkout, I was concentrating my
> investigation on ASTIdentifier, did I miss something or should I be
> looking elsewhere?

The ASTIdentifier.init() figures out whether it's dealing
with a property or a Map. There is an AbstractExecutor, and
MapExecutor and PropertyExecutor subclasses. The executor is
store for the subsequent renderings. The Introspector is not
used in the ASTIdentifer (maybe it should be), but the results
of determining whether it's a Map or Property are stored for
future use.

-- 
jvz.

Jason van Zyl
jvanzyl@periapt.com


Re: introspection

Posted by John McNally <jo...@clearink.com>.
Jason van Zyl wrote:
> 
> On Thu, 9 Nov 2000, John McNally wrote:
> 
> > Was there a decision against allowing methods with empty arguments to be
> > specified without the ()?
> >
> > Example.
> >
> > $browser.isJavaScriptOK
> >
> > as opposed to
> >
> > $browser.isJavaScriptOK()
> >
> > It obviously wouldn't be too hard to add the first form, is anyone
> > opposed?
> 
> As a standard boolean property I think it should be supported
> in the #if directive. So if you have the following:
> 
> #if ($user.LoggedIn)

But wouldn't it be easier and more flexible to support the dropping of
empty () in general?  Why does Velocity not allow this when it was
something that could be done in WM?  I am thinking it is only a couple
of lines of code in ASTIdentifier, am I wrong?

Dropping the "is" would also be worthwhile, but then it also might be
good to check the "has" prefix as well.  I don't know if "has" in
allowed in beans, but it is in wide use.

> All results of introspection are cached after the first pass. Not
> only for properties but for all methods as well. The results
> of introspection are actually held in the AST itself in the
> pertinent nodes.

I guess I need to update my checkout, I was concentrating my
investigation on ASTIdentifier, did I miss something or should I be
looking elsewhere?

Thanks,
John McNally

Re: introspection

Posted by Jason van Zyl <jv...@periapt.com>.
On Thu, 9 Nov 2000, John McNally wrote:

> Was there a decision against allowing methods with empty arguments to be
> specified without the ()? 
> 
> Example.
> 
> $browser.isJavaScriptOK
> 
> as opposed to 
> 
> $browser.isJavaScriptOK()
> 
> It obviously wouldn't be too hard to add the first form, is anyone
> opposed?

As a standard boolean property I think it should be supported
in the #if directive. So if you have the following:

#if ($user.LoggedIn)

We would look for $user.isLoggedIn(). That's standard bean
stuff and I think we should support it.
 
> The backend programmer could fudge it with a getisJavaScript() method,
> but the isXXX format for boolean properties, is pretty standard.  And I
> don't see any reason why the empty () pair should be required.
> 
> Also,
> would there be much benefit in trying to cache the "correct"
> interpretation of a ASTIdentifier?  It would seem to me that the
> interpretation will not change in most circumstances. So if out of
> 1.  getisOK()
> 2.  get("isOK") or get(isOK)
> 3.  isOK()
> 
> #3 is correct, it would be good to check it first the next time the
> template is used.
> Thoughts?

All results of introspection are cached after the first pass. Not
only for properties but for all methods as well. The results
of introspection are actually held in the AST itself in the
pertinent nodes. 

-- 
jvz.

Jason van Zyl
jvanzyl@periapt.com