On Thu, Sep 21, 2000 at 10:59:19AM -0700, Steve Fink wrote:
> For lexicals, a use without a declaration makes no sense, because
> variables default to global (non-lexical).  A use without an
> initialization is of arguable utility, because your defined() tests may
> already be intended to check for that case, so you'd really rather that
> not be a warning. Do I have that right?

Yep.


> my $x;
> ...
> $y = $x;
> ...
> if (defined($y)) ...
> 
> Ugh. I'll have to think about that some more.

I'm usually pretty careful myself, saying something like:

    $y = defined($x) ? $x : undef;

or something equally useless (but I only notice now how useless it is).  Use
of uninitialized value warnings are so annoying now that giving them more
often is just going to annoy more people.


> Declaring a (lexical) variable without using it still seems like a
> useful addition; it's nearly the same as the existing "used once"
> warning. And I know it would be useful in my code, because it'll let me
> find obsolete local variables in my subroutines.
>
> I'm still wondering if it would be useful to heuristically warn if a
> global's value is never used, ignoring possible symbolic references,
> eval""s, etc. It might be a useful incremental improvement over the
> current use strict 'vars' analysis. But the current analysis already
> gives me spurious warnings at times, and this would increase their
> frequency.

Well, sure, if the check for a use ignores conditionals, it could be very
useful.  Isn't your whole point, though, to warn when the user uses a value,
in any way, that has never been initialized?  That's not quite the same
thing.


Michael
--
Administrator                      www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

Reply via email to