Re: Odd observation during debugging
Christopher Schultz <[email protected]>
| Newsgroups | gmane.comp.jakarta.velocity.user |
|---|---|
| Message-ID | <[email protected]> |
Nathan, On 7/11/12 1:35 PM, Nathan Bubna wrote: > On Wed, Jul 11, 2012 at 9:58 AM, Christopher Schultz > <[email protected]> wrote: >> Nathan, > ... >>> See VELOCITY-731 and VELOCITY-692 and others... >> >> Those were good to read: 1.6 introduced more consistent (if slower) >> treatment of references and then a setting was added to get the old >> behavior. >> >> Any idea if a future version of Velocity (maybe 2.x) will have the >> default value of that directive set to "false" so that toString will >> only be called for users who actually want that? >> >> While backward-compatibility is certainly a reasonable goal, this >> behavior kind of sucks... and I can't really think of too many cases >> where it makes sense. Good that there is a setting for it ;) > > Actually, i still consider it correct for a template language (which > is not the same as a scripting language) to treat render-as-empty as > false in an #if. So, my hope for 2.0 was to not to remove that > behavior, but to pre-empt it. On a somewhat related issue, we had been considering using "strict reference mode" except that -- at least using the current if-directive semantics, it's not practical to do things like this: #if($mymap && $mymap.containsKey('somekey') && !$mymap.get('somekey').isEmpty() && ...) ...because many of those individual parts of the predicate may end up returning something that is neither Boolean nor a Map, etc. and you *must* test them for non-null-ness before trying to use them, otherwise you risk an exception. Without disabling the 'toString' behavior in the configuration, there will be no way for these types of checks to execute without spewing lots of (in my case) useless String objects (not to mention the wasted time to generate them in the first place). I've seen the use of things like this on occasion: #if($myobject == $null) My understanding was that a null reference would never be considered equal to *anything*, even another null reference. Does the above actually work? And the "$null" is just a reference that is assumed to be null, right? When in strict-reference-mode, would that work since $null has (presumably) never been defined? Thanks, -chris
signature.asc
(application/pgp-signature, 307 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.17 (Darwin) Comment: GPGTools - http://gpgtools.org Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAlAEO6UACgkQ9CaO5/Lv0PDdEwCfeKBBhuweHrKaoYeIDkkNSx87 jWQAnjeGSMPnuhnsrKeYbWvu7GZ2lAZG =mRz1 -----END PGP SIGNATURE-----