So, i'm still of the opinion that having "empty" values be treated as false by #if( $foo ) is a good idea. so i thought i'd restart this conversation by reminding people that VTL is a display language; it is not meant to be a full scripting language. so, while an empty array or empty map may not be "falsey" to a script, the lack of anything in the array or map to display makes it quite falsey to a display language, no?
So, to recap, i propose that we change #if in 2.0 to treat the following values as false:
$obj that is null
$obj that is boolean false
$obj that returns false from a getAsBoolean method
$obj that is empty string ""
$obj that is empty array
$obj that returns true from an isEmpty() method (i.e. Collection and Map implementations)
$obj that returns null or empty string from a getAsString method
$obj that returns 0 from a length() or size() method
$obj that returns empty string from toString() method
i also propose that the order above be the order in which things are checked. This means that while we will still check toString(), it will not ever be called on any maps or lists or any object that bothers to implement a getAsBoolean, getAsString or isEmpty() method. Again to be more clear, if the object has a getAsBoolean(), isEmpty(), getAsString(), length(), or size() method, then we don't keep looking further. Once we find one of these methods, we return false if the result is falsey or true otherwise. This makes it easy for users to avoid expensive calls to toString() or even getAsString().
For those who want to distinguish between false and falsey or null and empty, they will have to use #if( $obj == $null ) or #if( $obj == false ) to be explicit about what they want to know. So, there is no loss of functionality involved here. It is merely a change to make empty values be treated as false by #if( $foo ) calls and simultaneously make it easy to avoid expensive toString() calls when using #if to test references.
Thoughts, tirades, minor objections?
p.s. the getAsString and getAsBoolean support will probably be checked in this evening.