Re: When is @_ undefined?



On 2012-01-19 22:57, Ben Morrow <ben@xxxxxxxxxxxx> wrote:
Quoth Shmuel (Seymour J.) Metz <spamtrap@xxxxxxxxxxxxxxxxxxxxxxxxxx>:
In <87ehuv3h8y.fsf@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>, on 01/19/2012
at 02:21 PM, Rainer Weikusat <rweikusat@xxxxxxxxxxx> said:

Because he has successfully been fooled into believing that Perl
variables don't start to exist in some well-defined state by the 'use
of uninitialized value!' warning.

Isn't undef a well defined state?

I think that was Rainer's point: Perl variables are never 'undefined' in
the sense of the C standard,

Nitpick: The C standard never talks about "undefined variables", only
about "undefined behaviour". The value of a variable which hasn't been
(explicitely or implicitely) initialized ist "indeterminate".

so the 'uninitialized value' warnings tend to be more noise than
useful. They certainly aren't equivalent to the 'variable used without
being assigned a value' warnings C compilers are so fond of, which
often do indicate genuine bugs.

The 'uninitialized' warnings are badly worded. The warning really means
"you are using the value «undef» in a context where a defined value is
expected".


In perl's defence, they were much more useful back before 'my' and
'strict' were invented. In Perl 4 it was terribly easy to misspell a
variable name, and the only notice you got was (if you were lucky) an
'uninitialized value' warning. IMHO in Perl 5 they are redundant.

I don't think they are redundant. They are useful in cases where the
programmer thinks that a value should be defined but for some reason it
isn't. This usually indicates a bug.

Of course there are also situations in which the programmer *does*
expect a value to be undef and wants to treat it as '' or 0 - then it's
not a bug and the warning should be turned off. The 'uninitialized'
warning is certainly the warning I turn off most frequently. (The second
one is 'recursion' - if there are any others that I turn off, I do that
so infrequently I don't remember them).

hp

--
_ | Peter J. Holzer | Deprecating human carelessness and
|_|_) | Sysadmin WSR | ignorance has no successful track record.
| | | hjp@xxxxxx |
__/ | http://www.hjp.at/ | -- Bill Code on asrg@xxxxxxxx
.



Relevant Pages

  • Re: why wont perl say which value was uninitialized?
    ... who did a half-assed implementation of a warning for situation ... warning which happen to exist' (in a suitable version of perl), ... doesn't *necessarily* indicate an exceptional condition ... I didn't remember anything about defined/ undef from ...
    (comp.lang.perl.misc)
  • Re: why wont perl say which value was uninitialized?
    ... who did a half-assed implementation of a warning for situation ... Then what should print do with an undef ... warning which happen to exist' (in a suitable version of perl), ... doesn't *necessarily* indicate an exceptional condition ...
    (comp.lang.perl.misc)
  • Re: why wont perl say which value was uninitialized?
    ... a half-assed implementation of a warning for situation which is ... Then what should print do with an undef argument? ... what it is supposed to do: Print nothing aka 'an empty string'. ... doesn't *necessarily* indicate an exceptional condition ...
    (comp.lang.perl.misc)
  • Re: real basic..
    ... un BUG di Perl. ... Fai "man perl" e leggi...: ... accaduto *esattamente* il contrario, visto che *prima* esistevano dei warning obbligatori, che *poi* invece sono stati resi disattivabili: ...
    (it.comp.macintosh)
  • Re: [RegEx] Optional parameter
    ... variables start out with a value of 'undef' and this will be ... my $foo = undef; ... for cases where the intent is that $foo should be assigned a new value before ... are going to happen silently and which are going to trigger the warning. ...
    (comp.lang.perl.misc)