Byron,

I agree, for certain type of applications Velocity should be set to follow strict rules(mainly to throw exceptions as soon as possible instead logging). I know Nathan changed some parts to follow a strict mode and some sections throws exceptions now instead of logging the failure(actually both), but I think your idea with a more restrictive context could fill up some needs, at least I would like to have something like that. If the template access something that doesn't exists I would like to fail(fast).

Byron Foster wrote:

On Sep 29, 2008, at 4:34 , [EMAIL PROTECTED] wrote:

Hi,

Thanks for your thoughts (and possible contributions). Here some further ideas.

In the past the Velocity design avoided by all means to become Perl like.

I can appreciate that :)

Since there is a simpler workaround, I believe a "~=" operator can be avoided (in Perl it would mean to be a pattern matcher).

I've got a patch I will post next for review/feedback which uses the following syntax: #set($!foo = "bar"). The bang was pretty easy to implement with the current code (No parse alterations), and I think the syntax works.

So please use:
 #if($foo == $null)#set($foo = "bar")#end

This works fine now, but I'm making a setting that will throw an exception for variables and method that are not defined. In this context the if statement would not work because $foo would not be defined yet, causing an exception to be thrown.


or (using a context tool in the context):
 #if(!$context.isKey($foo))#set($foo = "bar")#end
or wrap the above in a macro and use it:
 #optionalDefault($foo "bar")

Fair enough, even though I might think it's a little obscure.

On the null reference issue, I proposed in an early Velocity to allow a silent assign notation, in the line of:
 #set($!foo = null)
to allow foo=null and to not log anything. This approach would allow the designer to specify where he expects nulls to go through. Unhappily it overlapped with another patch and did not make it into the core.

Ahh, well I used the same syntax in the coming patch, but for a different purpose.

To my knowledge since velocity 1.6 (1.5?) a null value can be assigned to a context key, when enabled by a property.

Not really, currently it is implement such that if a variable is assigned null, then the variable is deleted from the context. While currently this distinction is of little consequence, if variables must be strictly defined then it is important that #set($foo = $null) is still considered a set variable, and carried in the context.

Currently the notation
 #set($foo = $!bar.baz)
should not log if baz is undefined. You should also consider this silent notation operator in your object check.

But my intent is for this NOT to be silent if baz is undefined, but rather immediately throw an exception! and to take this one step further, throw an exception if even $bar is not defined.

Combining this with my proposed syntax:
 #set($!foo = $!bar.baz)
means to not complain that baz is null and silently assign it to the $foo in the context.

I believe there is a group of us Velocity users which would like to see references handled more strictly. I realize this is a preference, so I had intended, of course, to create an option to turn such behavior on using 'runtime.references.strict'. In my personal experience, whenever a property is undefined, or a variable, it is always because of a typo, or because code has been re-factored and a property doesn't exist anymore. In my usage the current behavior makes finding these problems difficult, especially when such referenced are buried several macro levels deep. It also makes unit testing trickier, for me at least :)




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to