velocity-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nathan Bubna (JIRA)" <>
Subject [jira] Commented: (VELOCITY-692) have #if handle empty strings/arrays/collections/maps more conveniently
Date Fri, 13 Feb 2009 20:48:59 GMT


Nathan Bubna commented on VELOCITY-692:

You could always do #if( $foo == $null ) to check for null instead of empty.  Personally,
i see #if as a shortcut for "falsey" values, and it doesn't seem that odd to me to include
empty objects in the "falsey" category.   Personally, i think if $rectangle.length() equals
0, i don't see why that should be considered any less empty or falsey than an empty string.
  If we're going to add "emptiness" to the things that #if considers false, then i would much
prefer to use reflection and add all empty things, rather than pick and choose.  So for me,
the question is simply whether to have the list of falsey things be just:




heck, i wouldn't even object to treating the number 0 and the string "false" as falsey also.
  if someone wants to be specific about what falsiness they are checking on, they should always
be specific and do:

#if( $foo == $null )
#if( $foo == false )
#if( $foo.length() == 0 )
#if( $foo.isEmpty() )

Using #if( $foo ) is always a fuzzy shortcut.  I think it's perfectly legitimate to have it
be a shortcut for checking emptiness too.

> have #if handle empty strings/arrays/collections/maps more conveniently
> -----------------------------------------------------------------------
>                 Key: VELOCITY-692
>                 URL:
>             Project: Velocity
>          Issue Type: New Feature
>          Components: Engine
>            Reporter: Nathan Bubna
>            Priority: Trivial
> An idea from the dev list:
> -------------------------------------------------------------------------------------------------
> On Sat, Feb 7, 2009 at 3:41 PM,  <> wrote:
> > Hello,
> > I wanted to share with you a few ideas I have about new simple
> > improvements for DisplayTools. I should be able to make patches for
> > them if you are interested.
> >
> > 1. Add new method
> >
> > isEmpty(object)
> >
> > that will return true if the object is null or empty (for strings it's
> > zero length; for collections, maps and arrays it's zero size). This
> > should help with  annoying null checks. (Probably a better place for
> > this method would be Engine, not Tools)
> yeah, not something for tools.  would be interesting to have the
> Uberspect pretend that every non-null reference has an isEmpty()
> method, or perhaps just add 0-length strings, empty collections, empty
> maps and 0-length arrays to the list of things that #if( $foo )
> considers false.
> -------------------------------------------------------------------------------------------------

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message