all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: "Juanma Barranquero" <lekktu@gmail.com>
Cc: "山本和彦 Kazu Yamamoto" <kazu@iij.ad.jp>, emacs-devel@gnu.org
Subject: Re: unused local variables
Date: Fri, 30 Nov 2007 10:58:38 -0500	[thread overview]
Message-ID: <jwv1wa73f8v.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <f7ccd24b0711300731u4286a3dfua8746ea43e83a90a@mail.gmail.com> (Juanma Barranquero's message of "Fri, 30 Nov 2007 16:31:31 +0100")

>> 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	other threads:[~2007-11-30 15:58 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-29 12:32 unused local variables Kazu Yamamoto
2007-11-29 15:31 ` Thien-Thi Nguyen
2007-11-30  0:23   ` Kazu Yamamoto
2007-11-30  9:22     ` Juanma Barranquero
2007-11-30  9:27       ` Kazu Yamamoto
2007-11-30  9:37         ` Juanma Barranquero
2007-11-30  9:59           ` David Kastrup
2007-11-30 10:14             ` Juanma Barranquero
2007-11-30 10:23               ` David Kastrup
2007-11-30 10:26                 ` Juanma Barranquero
2007-11-30 10:36                   ` David Kastrup
2007-11-30 10:49                     ` Juanma Barranquero
2007-11-30 10:34           ` Kazu Yamamoto
2007-11-30 10:45             ` Juanma Barranquero
2007-11-30 11:26               ` David Kastrup
2007-11-30 11:39                 ` Juanma Barranquero
2007-12-03  2:30               ` Kazu Yamamoto
2007-12-03  9:50                 ` Juanma Barranquero
2007-12-03 10:03                   ` Kazu Yamamoto
2007-11-30 15:10           ` Stefan Monnier
2007-11-30 15:31             ` Juanma Barranquero
2007-11-30 15:58               ` Stefan Monnier [this message]
2007-11-30 16:40                 ` David Kastrup
2007-11-30 17:58                   ` tomas
2007-11-30 18:07                 ` Juanma Barranquero
2007-11-30 15:38             ` Juanma Barranquero
2007-11-30 15:59               ` Stefan Monnier
2007-11-30 18:11                 ` Juanma Barranquero
2007-12-01  3:17                   ` Stefan Monnier
2007-11-29 16:02 ` Stefan Monnier
2007-11-30  0:25   ` Kazu Yamamoto
2007-12-04 11:12 ` Katsumi Yamaoka
2007-12-04 15:28   ` Dan Nicolaescu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwv1wa73f8v.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@gnu.org \
    --cc=kazu@iij.ad.jp \
    --cc=lekktu@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.