R
Rainer Weikusat
Coming to think of this, I'd agree that automatically converting a
non-numerical string to a number with value zero is rarely useful and
likely to lead to unpleasnt surprises, eg
[rw@sable]/tmp#perl -e 'print "David" == "Nick", "\n"'
1
(although this could be referred to 'deeper insight')
That's consistent with how atoi/ strtol would behave,
-----------
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
printf("%d\n", atoi("Salad") == atoi("Steak"));
return 0;
}
----------
but that's more likely to be an 1970s implemenetation shortcut than a
conscious semantic choice and in any case, someone who knows Perl won't
necessarily/ shouldn't need to know C as well.
OTOH, I think the so-called 'undefined value', at least insofar it is
used as default value of an uninitialized variable, should be an
exception here: A variable with 'no value' should behave as if it had
some 'neutral value' for the context it is used in: Explicit
initialization should only be necessary when something other like than
this 'neutral value' is needed. Forcing people to write
my $a;
$a = 0;
print($a + 1);
instead of
my $a
print($a + 1);
just clutters the code with a lot of 'self-evident' statements.
non-numerical string to a number with value zero is rarely useful and
likely to lead to unpleasnt surprises, eg
[rw@sable]/tmp#perl -e 'print "David" == "Nick", "\n"'
1
(although this could be referred to 'deeper insight')
That's consistent with how atoi/ strtol would behave,
-----------
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
printf("%d\n", atoi("Salad") == atoi("Steak"));
return 0;
}
----------
but that's more likely to be an 1970s implemenetation shortcut than a
conscious semantic choice and in any case, someone who knows Perl won't
necessarily/ shouldn't need to know C as well.
OTOH, I think the so-called 'undefined value', at least insofar it is
used as default value of an uninitialized variable, should be an
exception here: A variable with 'no value' should behave as if it had
some 'neutral value' for the context it is used in: Explicit
initialization should only be necessary when something other like than
this 'neutral value' is needed. Forcing people to write
my $a;
$a = 0;
print($a + 1);
instead of
my $a
print($a + 1);
just clutters the code with a lot of 'self-evident' statements.