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:
> Actually, i still consider [the toString behavior] 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 your large lists, it would never get
> around to checking toString(), since it would find isEmpty() and use
> that.  IMHO, the lookup order ought to be something like this:
> 
> #if( $obj ) will be false if:
> 
> $obj is null
> $obj is boolean false
> $obj returns false from getAsBoolean()
> $obj is empty string (CharSequence w/length 0)
> $obj returns true from isEmpty()
> $obj is array of length 0
> $obj returns null from getAsString()
> $obj returns empty string from getAsString()
> $obj returns null from getAsNumber()
> $obj returns empty string from toString()

If the ordering of the checking is really done that way, then my huge
lists (which shouldn't exist in the first place, really -- I know that
part's my fault) would fall-through at case #5 (isEmpty)? It's not
entirely clear to me what happens in this (List) case.

> So the config switch would stay, but in far more cases, it would be
> unnecessary.  The vast majority of slow toString() impls are
> collections or maps.  Other custom objects (see Apache Click) would
> easily be able to avoid toString() by having an isEmpty() or
> getAsBoolean() method.

And these would be introspected so they don't have to implement some
kind of interface, right?

After banging my head against my own code trying to figure out why my
non-template-defined Lists weren't being wrapped, I realized that the
contents of the Request/Session/Application attributes are *not* copied
into the Context... they are fetched when requested. That means my code
needs to get a bit more complicated if I want to wrap collections that
are fetched from the request attributes ;)

This code is really crappy... but do you think it would be useful for
anyone? I'd be happy to post it somewhere.

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/

iEYEARECAAYFAk/9wIAACgkQ9CaO5/Lv0PDKqwCdFu1nbJxS6CEC+RFzAeXvWNk/
7pIAn3Zy7SGjGILTAe38Pxi4Z8QXAoHn
=AmpC
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.