unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: rms@gnu.org
Cc: eggert@cs.ucla.edu, emacs-devel@gnu.org
Subject: Re: Should undefined behavior be encouraged in Emacs?
Date: Mon, 03 Oct 2011 18:14:01 +0200	[thread overview]
Message-ID: <83ipo6rr1y.fsf@gnu.org> (raw)
In-Reply-To: <E1RAiKS-0001xp-Pd@fencepost.gnu.org>

> Date: Mon, 03 Oct 2011 09:13:08 -0400
> From: Richard Stallman <rms@gnu.org>
> Cc: emacs-devel@gnu.org
> 
>     My impression is that Emacs built-ins are generally supposed to
>     have defined behavior, so that Emacs is easier to use reliably.
> 
> What is the meaning of "defined" or "undefined", here?
> Is it a matter of whether the documentation says what happens in that case?

Undefined behavior is something that is left to the implementation,
and the programmer who invokes it cannot expect anything in
particular.  Examples (from C) are use of an automatic variable before
initializing it, indexing an array outside of its bounds, etc.  These
could work, or they could produce strange results, or they could
crash.

I consider referencing buffer position of zero similar to indexing an
array out of its bounds.

> In simple cases such as (goto-char -5), users tend to see what the
> behavior is, and are likely to write code that depends on it, even if
> it isn't documented.  Thus, leaving it undocumented doesn't mean that
> we can change it and nobody will notice.
> 
> Meanwhile, even if something is documented, we CAN change it.
> It just means somewhat more annoyance will occur.

Documentation is not the issue here.  The issue is whether we should
let people expect certain undefined behaviors and demand that any such
behavior invariably produces results they expect.  To continue one of
the above examples, the expectation that an uninitialized automatic
variable in a C program always has the value of zero, or that
accessing an array out of bounds actually access its first or last
element, whichever is closest to the invalid reference.

When a large enough body of Lisp programs has been written that relies
on such behavior, any significant changes in the underlying
implementation are either very hard or very bug-prone (or both),
because no living individual can possibly study enough Lisp programs
to glean all these expectations and design the modified implementation
so as not to break them.



  parent reply	other threads:[~2011-10-03 16:14 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-03  1:39 Should undefined behavior be encouraged in Emacs? Paul Eggert
2011-10-03  3:11 ` Stefan Monnier
2011-10-03  6:39   ` Andreas Röhler
2011-10-03  7:29     ` Stephen J. Turnbull
2011-10-03  8:58       ` Andreas Röhler
2011-10-06  2:17         ` Stephen J. Turnbull
2011-10-06 17:30           ` Richard Stallman
2011-10-06 19:49             ` Stephen J. Turnbull
2011-10-06 20:08               ` Andreas Röhler
2011-10-06 20:12                 ` Lars Magne Ingebrigtsen
2011-10-06 20:46                   ` Eli Zaretskii
2011-10-07  5:23                   ` Andreas Röhler
2011-10-07  7:44                   ` Stephen J. Turnbull
2011-10-07  7:52                     ` John Wiegley
2011-10-07 17:27                       ` Stephen J. Turnbull
2011-10-07  8:38                   ` Alan Mackenzie
2011-10-07 15:26                   ` Barry Warsaw
2011-10-07 18:06                     ` ken manheimer
2011-10-07 18:21                       ` Barry Warsaw
2011-10-07 18:46                       ` Óscar Fuentes
2011-10-07 19:59                         ` ken manheimer
2011-10-07 18:41                     ` Drew Adams
2011-10-08 13:49                   ` Miles Bader
2011-10-08 14:34                     ` Drew Adams
2011-10-03 13:16       ` Stefan Monnier
2011-10-03  9:20   ` Alan Mackenzie
2011-10-03  9:52     ` Eli Zaretskii
2011-10-03  8:29 ` Andreas Schwab
2011-10-03  9:53   ` Eli Zaretskii
2011-10-03 13:13 ` Richard Stallman
2011-10-03 15:15   ` Dave Abrahams
2011-10-04  1:55     ` Richard Stallman
2011-10-04  2:18       ` Dave Abrahams
2011-10-03 16:14   ` Eli Zaretskii [this message]
2011-10-03 16:27     ` Andreas Schwab
2011-10-03 16:41       ` Eli Zaretskii
2011-10-04  1:55     ` Richard Stallman
2011-10-03 20:53   ` Paul Eggert
2011-10-03 14:49 ` Dave Abrahams

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=83ipo6rr1y.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=eggert@cs.ucla.edu \
    --cc=emacs-devel@gnu.org \
    --cc=rms@gnu.org \
    /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 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).