[Top][All Lists]

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


From: Luc Teirlinck
Subject: defconst
Date: Sun, 14 Nov 2004 12:33:47 -0600 (CST)

I believe that `defconst' is a relatively widely misused function.  I
believe that it should only be used for something that is an absolute
constant.  Yet people seem to use it for such things as variables that
should only be changed by the user but not by Lisp code, or vice-versa,
or variables that have no effect when changed with setq (but only if a
function is called), and any other of a number of situations where
changing the value of a variable has to be done carefully, or only in
certain situations.

Using `defconst' instead of `defvar' is much more than just a
stylistic error.  If the file gets reloaded, then the defconst, unlike
defvar, will override any changes made thus far in the Elisp session,
behind the user's back.  This can be very confusing to the user.
Thus, it should only be used if _any_ change to the variable in any
way would be wrong.  If in doubt, I believe one should always use defvar.

Maybe `defconst' is OK for version numbers.  They are not necessarily
constants, but if a new version of a package is loaded, the old
version number should indeed be overridden.

I only will handle uses of defconst that produced compiler warnings.
I am afraid that the problem is more widespread.

Compiler warnings are produced by defconsts in the viper package,
cust-print.el, tpu-edt.el, life.el and lao.el.

It appears that the vast majority of the many defconsts in the viper
package should be defvar's.  I hope that the author of viper.el still
maintains the package and can take a look at this.

For the four other files, I will propose concrete changes.

I CC-ed the authors of the viper, tpu-edt and life packages. 



reply via email to

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