emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: unused local variables


From: Stefan Monnier
Subject: Re: unused local variables
Date: Fri, 30 Nov 2007 10:58:38 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.50 (gnu/linux)

>> Yes.  And that's good.
> As I've said, I'm all for a lexically-scoped elisp. But I'm a bit
> worried by introducing warnings for things that are not "wrong" (or,
> at least, weren't until now).

Those warnings do catch left-over unused variables as well.
And they can easily be silenced by adding a `defvar'.

>> E.g. if you want to compile this file with the
>> lexical-scoping version of Emacs that Miles has been working on, this
>> is indispensable.
> Any hope of that branch merged with the trunk sometime?

No idea.  But I hope so.

>> BTW, in the above example, the byte-compiler already complains in the
>> `test' function, so it's not like it's going to make that big
>> a difference.
> As shown in a previous message, there's no warning if the function
> tests whether my-dynamic-variable is bound.

Sure.  Now, find me an example of a use of `boundp' on a variable for
which there exist no defvar.

>> Also dynamic scoping is sufficiently odd and rarely used that it deserve
>> special mention in the code.  It's pretty common to mark it with
>> a comment.  And code is always better than a comment since it tends to
>> bitrot a bit less quickly.

> I agree that code is better than a comment. I'm not sure I agree that
> dynamic scoping is "odd and rarely used" in elisp packages.

Dynamic scoping is often used in Emacs to temporarily change the value
of a "global" variable (variables defined via a defvar somewhere).
It is rarely used for pure argument passing.  It is used that way, but
rarely.  And often those uses come with comments warning about it,
because programmers tend to assume lexical scoping (even when writing
Elisp).  At least that's my experience based on more than 10 years of
browsing emacs/lisp/**/*.el packages.

>> PS: Another "unused var" warning which we should add (I don't have it
>> in my lock hack yet, tho) is the one that notices when a `defvar'
>> declares a variable which is not used in the file.

> That one seems useful, yes. byte-compiler-silencing `defvar's (and now
> `define-function's), like `require's (and C #include's), tend to
> accumulate even when they cease to be necessary.

It will also give false positives.  Take a look at lisp/pcvs-defs.el for
a striking example where most of the defvars are not used in that file.
I guess a first step could be to limit its use to
"byte-compiler-silencing defvars".


        Stefan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]