develooper Front page | perl.perl6.language | Postings from May 2001

Re: Properties and "0 but true".

Thread Previous | Thread Next
From:
Austin Hastings
Date:
May 18, 2001 06:58
Subject:
Re: Properties and "0 but true".
Message ID:
20010518135817.6628.qmail@web1105.mail.yahoo.com

--- Jarkko Hietaniemi <jhi@iki.fi> wrote:
> On Fri, May 18, 2001 at 06:22:10AM -0700, Austin Hastings wrote:
> > Hmm. I can easily see this producing incomprehensible code when
> spread
> > across large systems. To wit, those developers used to "0 means
> false"
> 
> Any feature is incomprehensible if one is not used to it.  Pointers
> in C are incomprehensible if one has never met the concept before.
> 
> As far as I understand one rationale behind the "false (in Perl 5
> terms)
> but true (in Perl 6 terms)" is that you can write code like this
> 
> 	if ($retval = func(@args)) {
> 		# it worked ...
> 	} else {
> 		# it didn't ...
> 		# but we still can dig out more information
> 		# about the result ...
> 		print $retval.what_went_wrong, "\n";
> 	}

The statement I read was "true in any possible way", which implies that
if $retval had a "true" property, the result of func would be
irrelevant, since if func gave 0, "any possible way" would see the
"$retval is true" property and take the "it worked" route.

Thus, this code:

my $retval is true;

if ($retval = func(@args))
{
  # it worked...
}
else
{
  # nope...
  print $retval.what_went_wrong, "\n";
}

would execute the "it worked" case for all values of func(@args), which
to me seems to be asking for trouble.

Of course, if the scalar result can't have associated properties ...

Or, if the properties of a scalar are reset on assignment (cringe) ...

Perhaps 
> > semantics seeings a scalar that they just know has a 0 in it and
> > wondering why the branch isn't doing what they know it should.
> 
> Free your mind-- detach the truth of a scalar from its '0 or "" or
> undef'
> nature.

New from O'Reilly's offshore division?

"Perl CookBook, 4th edition. Crack pipe and 6 rocks included!"

I don't mind the presence of these potentially horribly confusing
thingys. After all, thanks to this list I'll be on the right side of
the learning curve. However, I don't think that "Poo, poo." is the
correct answer to "How about maintainability?" on anybody's multiple
choice exam.

=Austin


__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About