ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stephan beal <>
Subject Re: suggestion for if/unless syntax change
Date Thu, 21 Mar 2002 09:30:57 GMT
On Wednesday 20 March 2002 20:48 pm, Diane Holt wrote:
> --- stephan beal <> wrote:
> > i have a suggestion for the if/unless clauses:
> >
> > Rename them to ifset and unlessset. The reason for this is that they
> > have behaviour which is counter-intuitive for most programmers
> > in that they work if the var is set to *any* value, regardless of
> > the true/false interpretation of the var.
> I don't find it counter-intuitive. The if/unless attributes take the name
> of a property, not a reference to its value (ie., "foo", not "${foo}") --
> nor does setting a property to "true" or "false" mean anything special,
> generally, since they're just the strings t-r-u-e and f-a-l-s-e.

It's counter-intuitive when compared to the 'if' feature every programming 
language in the world. The strings true/false/yes/no DO have special meanings 
in ant - they are converted to the boolean values 'true' in many contexts. 
The fact that they aren't treated that way in some contexts (if/unless) is 
confusing - it's inconsistent not only with other languages, but also with 
ant's own normal handling of true/false/yes/no.

In a "normal" scripting language you could do this:

$foo = false;
if( $foo ) { 
  print "blah";
} # this'll never run

in ant, however, it would run.

Actually, in Perl it would evaluate to true if $foo was the string "blah", 
and in that sense it behaves like ant's 'if'. However, if $foo is set to "0", 
then it would evaluate to false in Perl, but true in ant (in the 'if' 
context, at least). i see your point, but i am still befuddled by the 
inconsistency. i'm used to it now, so i understand how to use it, but i shake 
my head every time i do ;).

A different, backwards-compatible feature which might make the use of 'if' 
more useful is adding an 'unset' attribute to <property>:

<property name='foo' unset/>

Then we can be sure that ${foo} is not set, in the case that we want to unset 
it for some tests, for example.

----- stephan
Generic Universal Computer Guy -
Office: +49 (89)  552 92 862 Handy:  +49 (179) 211 97 67
"I ain't gen'rally given to physicality of that nature but it saves
a lot of arguing." -- Nanny Ogg

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

View raw message