unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Re: constant `e'
@ 2007-02-13  2:34 djh
  2007-02-13  8:23 ` Werner LEMBERG
  0 siblings, 1 reply; 67+ messages in thread
From: djh @ 2007-02-13  2:34 UTC (permalink / raw)
  To: emacs-devel



From: Jay Belanger <belanger@truman.edu>
>David Hansen <david.hansen@gmx.net> writes:
>> Despite being a maths graduate, I can't think of any other such constants
>> with anything like the universality of e and pi.
>
> 42

>Perhaps we should introduce the constant `math-42'.
>Jay

42 is just the answer as I recall.
I'm not convinced that it needs to have a contant definition.

Darel Henman

^ permalink raw reply	[flat|nested] 67+ messages in thread
* constant `e'
@ 2007-02-09  7:37 Drew Adams
  2007-02-09  9:32 ` Juanma Barranquero
                   ` (4 more replies)
  0 siblings, 5 replies; 67+ messages in thread
From: Drew Adams @ 2007-02-09  7:37 UTC (permalink / raw)
  To: Emacs-Devel

A minor whine - ignore if you don't agree.

Single-character global variables are generally not such a great idea. In
particular, they can easily occur as typographical errors and not be
detected for a while.

The variable `e', defined in `float-sup.el', has been around for a long
time, but I wonder if it wouldn't be better to give it a different name in
Emacs, because of the possibility of `e' occurring as a typo.

[In fact, I wonder if much is gained in speed by defining it as a variable
at all, instead of just using its definition of (exp 1) whenever its value
is needed (or caching the value locally, when appropriate). I also wonder
why `pi' is a defconst but `e' is a defvar.]

`t' is similar, of course, but `t' as a typo is less surprising for anyone
at all used to Lisp. `e' as a numerical constant is not used in most
Emacs-Lisp code, so it is more likely that someone might be surprised by the
effect of an `e' typo (once discovered).

The position of `e' on many keyboards also makes it easy to hit when you
mean to hit a numeral key such as `3', and, unlike `t', the type of `e' is
numeric, so the value mismatch won't always lead to a type mismatch that
might make the error more apparent.

There are many other one-letter physical and mathematical constants.
Fortunately, their names are not used as the names of Emacs constants and
variables. `e' seems to be the exception. Even a two-letter name, such as
`pi', is much, much less error prone than a one-letter name.

Obviously, renaming `e' now would break existing code, but if others agreed,
then we might plan to deprecate `e' over time, in favor of a longer name.

Another possibility would be to change `e' to a function or macro, and
deprecate the variable over time. In that case too I'd prefer a longer name
than one character, but a one-character function or macro name is generally
less error-prone than a variable name. As mentioned above, another approach
(which I prefer, actually) would be to just drop `e' altogether and advise
people to use (exp 1). Anyone needing to use `e' would be likely to know
this definition, in any case.

BTW, this comment in `float-sup.el' is ironic.  It argues, itself, against
the library's defining `e':

 ;; Careful when editing this file ... typos here will be hard to spot.
 ;; (defconst pi       3.14159265358979323846264338327
 ;;  "The value of Pi (3.14159265358979323846264338327...)")

Perhaps that comment dated from some time (?) pre-Emacs 20 when `pi' was
defined using explicit decimal notation, as in the line that follows it, and
perhaps only mistyping numerals was meant, but I find it amusing when
thinking about the possibility of `e' typos. Unfortunately, the effect is
not confined to this library ("typos here") - `e' is a global name, and
`float-sup.el' is preloaded.

The best joke is not that self-referencing comment, but the fun someone
would have trying to find all occurrences of variable `e' in the existing
code, to rename them (and debugging missed or inappropriate renamings).
Undefining it and seeing what happens would be one approach... Obviously not
something to attempt before the release, in any case. ;-)

^ permalink raw reply	[flat|nested] 67+ messages in thread

end of thread, other threads:[~2007-02-13  8:23 UTC | newest]

Thread overview: 67+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-02-13  2:34 constant `e' djh
2007-02-13  8:23 ` Werner LEMBERG
  -- strict thread matches above, loose matches on Subject: below --
2007-02-09  7:37 Drew Adams
2007-02-09  9:32 ` Juanma Barranquero
2007-02-09 11:24   ` Kim F. Storm
2007-02-09 15:08   ` Stefan Monnier
2007-02-09 15:19     ` Juanma Barranquero
2007-02-09 15:34       ` Stefan Monnier
2007-02-10 17:40       ` Richard Stallman
2007-02-09 18:33     ` Jay Belanger
2007-02-09 18:51       ` Stefan Monnier
2007-02-09 14:23 ` Richard Stallman
2007-02-09 14:32   ` Leo
2007-02-09 23:11     ` Kim F. Storm
2007-02-10  0:16       ` Drew Adams
2007-02-12 18:11         ` Stuart D. Herring
2007-02-10 17:39     ` Richard Stallman
2007-02-09 14:37   ` David Kastrup
2007-02-10 17:39     ` Richard Stallman
2007-02-09 15:33   ` Drew Adams
2007-02-09 16:30     ` Eli Zaretskii
2007-02-09 16:50       ` Drew Adams
2007-02-10  9:49         ` Eli Zaretskii
2007-02-09 23:07   ` Dieter Wilhelm
2007-02-10 17:39     ` Richard Stallman
2007-02-10 18:41     ` Slawomir Nowaczyk
2007-02-10 21:12       ` Dieter Wilhelm
2007-02-10  9:29   ` Kevin Rodgers
2007-02-10 19:13     ` Stefan Monnier
2007-02-10 19:22       ` Lennart Borgman (gmail)
2007-02-10 19:38         ` Stefan Monnier
2007-02-10 20:32           ` Lennart Borgman (gmail)
2007-02-12  5:04             ` Kevin Rodgers
2007-02-12 16:06               ` Drew Adams
2007-02-10  6:27 ` Daniel Brockman
2007-02-10  8:59   ` David Kastrup
2007-02-10 11:35     ` Daniel Brockman
2007-02-10 12:01       ` David Kastrup
2007-02-10 12:42         ` Daniel Brockman
2007-02-10 12:43       ` Alan Mackenzie
2007-02-10 14:33         ` Daniel Brockman
2007-02-10 18:05           ` Alan Mackenzie
2007-02-10 18:29             ` Daniel Brockman
2007-02-12 19:03           ` Stuart D. Herring
2007-02-12 19:57             ` Daniel Brockman
2007-02-10 17:38         ` David Kastrup
2007-02-10 18:15           ` Daniel Brockman
2007-02-12 18:51           ` Stuart D. Herring
2007-02-10 19:05       ` Stefan Monnier
2007-02-10 20:48         ` Daniel Brockman
2007-02-10 21:06           ` Stefan Monnier
2007-02-11  9:42           ` David Kastrup
2007-02-11 17:53             ` Daniel Brockman
2007-02-10 21:34       ` Edward O'Connor
2007-02-12 19:17       ` Stuart D. Herring
2007-02-12 20:37         ` Daniel Brockman
2007-02-12 20:40           ` David Kastrup
2007-02-10 17:41   ` Richard Stallman
2007-02-10  9:02 ` Alan Mackenzie
2007-02-10  9:51   ` Jason Rumney
2007-02-12 18:16     ` Stuart D. Herring
2007-02-10 15:13   ` Juanma Barranquero
2007-02-10 19:12   ` Stefan Monnier
2007-02-11  0:43   ` David Hansen
2007-02-11  1:13     ` Jay Belanger
2007-02-11  1:24   ` Drew Adams
2007-02-10 18:53 ` Chong Yidong

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).