Tach,
wer sich nicht mehr daran erinnert da� schon in der Schule Wahrheit
ein keineswegs absoluter Begriff ist, sollte das sp�testens wissen
seit Powerpoint-folien als Beweise gelten.
Man kann als Programmmierer mit Wahrheitswerten allerdings auch
extrem viel Spass haben wie der folgende Email-wechsel auf der Fun
with Perl-liste beweist:
1)
I like to use symbolic constants. Wha can remember what all those
1, 0, undef, and ''s mean anyway? So I start off all my programs
with
use constant FALSE => !TRUE;
use constant TRUE => !FALSE;
Andrew
2)
I start off all my programs with use strict :-)
But more to the point, how do you use your TRUE and FALSE? Suppose
you
want to test the return value of this sub:
sub returns_a_true_value { 8.2 }
Would you do "if (returns_a_true_value() eq TRUE)"? "== TRUE"?
Neither would work, and you can just do "if (returns_a_true_value())"
directly anyway.
3)
> But 8.2 is not TRUE value. If returns_a_true_value is supposed to
> return a true true value, it should end with
>
> return TRUE;
>
> shouldn't it?
Well, no. If it is supposed to return "a" true value, then it
could return any true value, and 8.2 falls in that category.
On a related, less non-serious note, I seem recall it was fairly
standard in C, back in the old days, to write something like
#define FALSE !1
#define TRUE !FALSE
Since 1 is "a" true value, but TRUE is "the" true value.
(And of course FALSE is "the" false value.)
But that was in the days before standard C, which demanded
that FALSE always be zero.
Constants like this aren't (or shouldn't be) for testing,
only for setting.
4)
Umm, I think what you were trying for was
#define FALSE 0
#define TRUE (!FALSE)
5)
You may be joking, but I used to do things like this:
use constant TRUE => 1==1;
use constant FALSE => !TRUE;
use constant SUCCESS => TRUE;
use constant FAILURE => !SUCCESS;
use constant ERROR => undef;
and used it like...
sub is_foo {
...
return TRUE if $bleh eq 'foo';
}
on the grounds that "return 1" is ambiguous, are you returning the
number
1 or indicating truth?
I admit its rather overdoing it a bit. I got it from a notable bit
of
dubious advice in a book that's otherwise full of good advice, "Code
Complete". Their logic was that different programming languages have
different ideas of what truth is (for some, 0 is true) and you might
forget as you moved from one language to another.
So, das wars. Alles klar?
Bernd
At today's exchange rates 101 in binary is now worth just 5 in
decimal, following
a catastrophic devaluation of binary.
_______________________________________________
Coffeehouse mailing list
[EMAIL PROTECTED]
http://www.glengamoi.com/mailman/listinfo/coffeehouse