Michael Fowler wrote:
> 
> Ok, at this point I'm trying to clear up misunderstandings.  I believe you
> know where I stand with relation to your RFC.

Thanks, you caught several of my mistakes.

> 
> On Wed, Sep 20, 2000 at 06:41:52PM -0700, Steve Fink wrote:
> > Michael Fowler wrote:
> 
> > > Except for the line number reported, which is the important part.
> >
> > Oh. Certainly you'll get the line number. My description didn't include
> > it because it didn't seem to aid to the understanding. I have it in the
> > examples that I added to the RFC.
> >
> > I suppose it could even give both line numbers for declared variables:
> > "use at line 7 of uninitialized variable declared at line 3."
> 
> Yes, you could do that, but it wouldn't catch this problem.
> 
> The example code:
> 
>     $foobal = 3;    # This $foobal is an intentional typo.
>     if (@ARGV) { $foobar = @ARGV }
>     print $foobar;
> 
> I want perl to tell me that $foobal, declared on line 1, was never used.
> You want perl to tell me that $foobar, used on line 3, and declared on line
> 1 (!), was used uninitialized.  I'm going to assume you didn't mean perl
> should do code analysis to see exactly where I first misspelled the
> variable.  If it could, great!  Somehow I doubt we're going to go there,
> though.

I don't think of an assignment to a global as a declaration. Only C<my
$foo> is a declaration. I need to rewrite the RFC to pertain to both
lexicals and globals. I think I may have to leave current behavior
unchanged (it only considers globals), but add the simple flow analysis
for lexicals.

Typos in uses or assignments would then be caught by existing
mechanisms, because they wouldn't be declared lexical. Typos in
declarations would be caught by "use of uninitialized value", as well as
(probably) the existing mechanisms for the uses and assignments of the
correctly spelled variable.

So I guess I finally get what you've been trying to tell me: for typos,
the existing mechanisms are sufficient.

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? Then perhaps the warning
*should* be on by default, but suppressed if defined() is ever called on
the variable? That would still warn unnecessarily on

my $x;
...
$y = $x;
...
if (defined($y)) ...

Ugh. I'll have to think about that some more.

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.

> Yes, I realize that.  But more often than not the variables are used
> undefined to indicate a certain state, and you want me to either insert a
> "no warnings 'whatever'", or initialize all of those variables to undef
> explicitly.  I'm saying I want the code to work the same, because perl
> already tells me about the use of uninitialized values, and my having used a
> variable only once.
> 
> In fact, I don't want it to mention I've used it only once when I use use
> strict and declare my variables; strict catches my misspellings, and at
> compile-time, no less.

Got it. I think.

Reply via email to