From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: unused local variables Date: Fri, 30 Nov 2007 10:58:38 -0500 Message-ID: References: <87wss1qd9e.fsf@ambire.localdomain> <20071130.092322.193982611.kazu@iij.ad.jp> <20071130.182726.126856507.kazu@iij.ad.jp> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1196438377 2159 80.91.229.12 (30 Nov 2007 15:59:37 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 30 Nov 2007 15:59:37 +0000 (UTC) Cc: =?utf-8?B?5bGx5pys5ZKM5b2mIEthenUgWWFtYW1vdG8=?= , emacs-devel@gnu.org To: "Juanma Barranquero" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Nov 30 16:59:45 2007 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1Iy8Gd-0005xq-3n for ged-emacs-devel@m.gmane.org; Fri, 30 Nov 2007 16:59:03 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Iy8GN-0000hr-5m for ged-emacs-devel@m.gmane.org; Fri, 30 Nov 2007 10:58:47 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Iy8GI-0000fL-Cs for emacs-devel@gnu.org; Fri, 30 Nov 2007 10:58:42 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Iy8GH-0000e6-LI for emacs-devel@gnu.org; Fri, 30 Nov 2007 10:58:41 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Iy8GH-0000dn-9K for emacs-devel@gnu.org; Fri, 30 Nov 2007 10:58:41 -0500 Original-Received: from tomts10-srv.bellnexxia.net ([209.226.175.54]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Iy8GG-0005uL-Rc for emacs-devel@gnu.org; Fri, 30 Nov 2007 10:58:41 -0500 Original-Received: from toip5.srvr.bell.ca ([209.226.175.88]) by tomts10-srv.bellnexxia.net (InterMail vM.5.01.06.13 201-253-122-130-113-20050324) with ESMTP id <20071130155839.CPLA1733.tomts10-srv.bellnexxia.net@toip5.srvr.bell.ca> for ; Fri, 30 Nov 2007 10:58:39 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ah4FABfCT0dGN4zh/2dsb2JhbACBW480 Original-Received: from bas1-montreal42-1178045665.dsl.bell.ca (HELO pastel.home) ([70.55.140.225]) by toip5.srvr.bell.ca with ESMTP; 30 Nov 2007 11:00:54 -0500 Original-Received: by pastel.home (Postfix, from userid 20848) id 7467D7F62; Fri, 30 Nov 2007 10:58:38 -0500 (EST) In-Reply-To: (Juanma Barranquero's message of "Fri, 30 Nov 2007 16:31:31 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.50 (gnu/linux) X-detected-kernel: by monty-python.gnu.org: Solaris 8 (1) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:84361 Archived-At: >> 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