For and against muddling booleans

What is true and what is false, 0, 1, undefined, ""?

One frequent source of bugs in Perl programs is confusing true/false tests in if statements with numerical values.

This error in the following code:

for my $key (qw!
    !) {
	if ($pattr->{$key} && ! defined $attr{$key}) {
	    $attr{$key} = $pattr->{$key};

resulted in the following rendering error (correct SVG output on the left, bad output on the right):

The value of stroke-opacity was set to zero, but this was not transmitted from the parent attribute pattr to the current attributes attr because the “if” test on $pattr->{$key} failed. The way to work around this in Perl is to add the defined keyword. C is also similar, a value of 0 is a “false” value and 1 or other non-zero integers are all “true”.

In Go, it’s insisted that what comes after an if statement must be either true or false, so one cannot use 0 or 1 or an empty string or whatever to mean true/false. Although it is slightly annoying, this results in many fewer errors in practice.

Incidentally this stroke-opacity being set to zero seems to be some kind of bug in the Super Tiny Icons collection. Reported here.