all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Drew Adams" <drew.adams@oracle.com>
To: "'Uday Reddy'" <uDOTsDOTreddy@cs.bham.ac.uk>, <help-gnu-emacs@gnu.org>
Subject: RE: `save-excursion' defeated by `set-buffer'
Date: Sun, 13 Mar 2011 11:22:50 -0700	[thread overview]
Message-ID: <9F726D3B418A4DB6BF58058E2A8C880D@us.oracle.com> (raw)
In-Reply-To: <4d7c335d$0$23757$14726298@news.sunsite.dk>

> > But this has already been expressed (by several people), 
> > and rejected, in various discussions in emacs-devel@gnu.org.
> 
> I believe I was the one that last raised it in emacs-devel and, after 
> the explanations from Stefan Monnier and Stephen Turnbull, I was 
> satisfied.  I told you quite explicitly that I was satisfied.

So?  As I said, the warning was discussed, and getting rid of it was rejected.
You are convinced that that's a great decision; I am not.  No way of knowing
what most people felt or feel, and it doesn't matter because polls are not taken
anymore when deciding...  (Poor Emacs.)

> > IMO, this warning has produced _far_ more confusion than it 
> > has eliminated.  And that will no doubt continue to be the
> > case going forward.
> 
> Yes, I agree that this saga will continue for quite some time.  But I 
> wouldn't say that the warning has produced all this confusion.  The 
> confusion about how to use save-excursion correctly has existed for a 
> long time and continues to exist.  The warning is the 
> messenger, not the cause of the confusion.

I'm not convinced of the existence of this bogeyman about mass confusion
concerning how to use `save-excursion'.  I don't see such confusion.

But it's pretty _obvious_ that the warning message has produced a colossal
amount of confusion.  Everybody and her brother has a different understanding of
what the "danger" might be.

> > FWIW, I also agree with Andreas that a "warning" is for 
> > something serious.  A warning is not the same thing as in
> > informative message.  A warning _warns_ you about potential
> > danger/damage.  Alarmism eventually results in the Chicken
> > Little effect (aka Boy Cries "Wolf!").
> 
> This particular warning is in the 'suspicious category.
> It signals that the code is suspicious.

Only if you think that using `save-excursion' with `set-buffer' is suspicious,
which in general it is not.

Wrt the supposed danger, David K replied this to Stefan (who replied to me,
defining the danger)
http://lists.gnu.org/archive/html/emacs-devel/2010-01/msg00588.html:

>>> just what is inherently wrong or dangerous (meriting a
>>> warning) with code like the following, to do some work in other buffers yet
>>> return to the original buffer AND restore its point and mark?
>>>
>>> (save-excursion
>>>   (set-buffer FOO)
>>>   ; Pick up some info in FOO, & perhaps assign it to a var
>>>   (set-buffer BAR)
>>>   ; Calculate something in BAR, & perhaps record it too
>>>   ...
>>> )
>>
>> What is dangerous about it is that dependong on which buffer is current
>> before executing this code, the point-saving will either do something
>> or nothing.
>
> Wrong.  It will always restore the _original_ buffer and its point on
> exit of the save-excursion form.

David is correct of course.  And Stefan's explanation of the "danger" does not
indicate any danger, in any case.  Where's the beef?

> I for one would be very wary of using anybody's code that generates
> such warnings.

That is precisely one of the problems created by this misguided message.  Users
get freaked out seeing WARNINGs when they byte-compile the code.  They don't
understand the message (even seasoned developers differ in their guesses as to
its meaning), and the unknown scares them.

Even Stefan admits that the compiler is incapable of issuing such warnings only
when the code is in fact problematic in his eyes.  In plain English, it's stupid
and warns about situations that even Stefan admits are not a problem.  And much
of the `save-excursion' code that he would consider problematic is in fact
typically safe, sound, and sure.

IOW, the warnings are all over the map - "tales told by an idiot, full of sound
and fury, signifying nothing".

Whether or not every use of `save-excursion' with `set-buffer' is stylistically
neat or is the best choice in terms of software engineering is a different
matter.  And it is a matter that is not handled discriminately by this message,
in any case.

> The warnings would signal to me that the developers have not
> taken care to use the programming language correctly.

If they automatically signal that to you, then I would suggest that you might
not have taken sufficient care to learn the programming language correctly. ;-)

More seriously, RMS et al who created `save-excursion' were not idiots.  They
explicitly designed it to save and restore which buffer is current, in addition
to its point and mark.  Why, do you suppose?

And most users of it over the years have used it well - without any warnings.
If you automatically think that such a warning indicates bad code or inadequate
knowledge of Emacs Lisp then you are jumping to a wild, indiscriminate
conclusion, IMO.

> They have produced code that happens to work but 
> could break easily when pulled and stretched.

You cannot deduce that from the warnings issued.  They might have; they might
not have.  Not every use of `save-excursion' with `set-buffer' indicates
fragile, messy, or otherwise unwise code.

Far from it.  You yourself mentioned zillions of such uses in the code you
inherited, only a tiny minority of which you felt needed correcting.  And you
certainly didn't need a warning for each occurrence in order to search your code
for possible improvements.




  reply	other threads:[~2011-03-13 18:22 UTC|newest]

Thread overview: 113+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.0.1299085819.4487.help-gnu-emacs@gnu.org>
2011-03-02 20:54 ` `save-excursion' defeated by `set-buffer' Uday Reddy
2011-03-05  4:28 ` Stefan Monnier
2011-03-10 19:57   ` Andreas Röhler
2011-03-11  1:07     ` Leo
2011-03-11  1:28     ` Stefan Monnier
2011-03-11  8:52       ` Andreas Röhler
     [not found]       ` <mailman.25.1299833256.26376.help-gnu-emacs@gnu.org>
2011-03-11  9:54         ` David Kastrup
2011-03-11 11:09           ` Andreas Röhler
     [not found]           ` <mailman.10.1299841456.13496.help-gnu-emacs@gnu.org>
2011-03-11 11:38             ` David Kastrup
2011-03-11 15:52         ` Stefan Monnier
2011-03-12  8:59           ` Eli Zaretskii
2011-03-12 19:00             ` Andreas Röhler
2011-03-12 19:56               ` Drew Adams
2011-03-12 20:27                 ` Eli Zaretskii
2011-03-12 22:20                   ` Drew Adams
2011-03-14 18:59                 ` Juanma Barranquero
2011-03-14 21:17                   ` Drew Adams
     [not found]               ` <mailman.6.1299959800.9013.help-gnu-emacs@gnu.org>
2011-03-13  3:00                 ` Uday Reddy
2011-03-13 18:22                   ` Drew Adams [this message]
     [not found]                   ` <mailman.0.1300040583.10860.help-gnu-emacs@gnu.org>
2011-03-14  1:04                     ` Uday Reddy
2011-03-14  8:43                       ` Drew Adams
     [not found]             ` <mailman.4.1299956141.9013.help-gnu-emacs@gnu.org>
2011-03-12 22:29               ` Tim X
2011-03-13  7:15                 ` Andreas Röhler
2011-03-13 18:23                   ` Drew Adams
2011-03-13 12:46                 ` Uday S Reddy
2011-03-14  8:47                   ` Drew Adams
     [not found]                   ` <mailman.7.1300092490.2602.help-gnu-emacs@gnu.org>
2011-03-14 12:22                     ` Uday Reddy
2011-03-14 14:20                     ` Uday S Reddy
2011-03-14 17:36                       ` Drew Adams
2011-03-14 23:20                         ` Uday S Reddy
2011-03-15  3:55                           ` Drew Adams
     [not found]                       ` <mailman.14.1300124226.2531.help-gnu-emacs@gnu.org>
2011-03-15 14:39                         ` Stefan Monnier
2011-03-15 15:59                           ` Drew Adams
     [not found]                           ` <mailman.2.1300204800.1264.help-gnu-emacs@gnu.org>
2011-03-15 17:46                             ` Stefan Monnier
2011-03-15 18:55                               ` Drew Adams
2011-03-14 14:18                   ` Andreas Röhler
     [not found]                   ` <mailman.5.1300111985.27831.help-gnu-emacs@gnu.org>
2011-03-14 14:54                     ` Uday Reddy
     [not found]                 ` <mailman.5.1300000253.31664.help-gnu-emacs@gnu.org>
2011-03-13 14:16                   ` Uday Reddy
2011-03-13 18:25                     ` Drew Adams
     [not found]                     ` <mailman.2.1300040743.10860.help-gnu-emacs@gnu.org>
2011-03-13 20:48                       ` Uday Reddy
2011-03-14  0:31                         ` Drew Adams
     [not found]                 ` <mailman.4.1300066631.25374.help-gnu-emacs@gnu.org>
2011-03-14 14:34                   ` Stefan Monnier
2011-03-13  2:11               ` Uday Reddy
2011-03-13 18:26                 ` Drew Adams
     [not found]           ` <mailman.5.1299920357.7270.help-gnu-emacs@gnu.org>
2011-03-12  9:34             ` David Kastrup
2011-03-12 10:12               ` Eli Zaretskii
     [not found]               ` <mailman.10.1299924724.7270.help-gnu-emacs@gnu.org>
2011-03-12 10:42                 ` David Kastrup
2011-03-12 12:28                   ` Eli Zaretskii
2011-03-12 15:17                   ` Uday Reddy
2011-03-12 15:25                     ` David Kastrup
2011-03-13  2:40                       ` Uday Reddy
2011-03-14 14:25                         ` Stefan Monnier
2011-03-14 17:26                           ` Andreas Röhler
     [not found]                           ` <mailman.11.1300123292.2531.help-gnu-emacs@gnu.org>
2011-03-15 14:35                             ` Stefan Monnier
2011-03-15 14:47                               ` David Kastrup
2011-03-15 15:19                               ` PJ Weisberg
2011-03-15 16:00                               ` Drew Adams
     [not found]                               ` <mailman.6.1300202904.14512.help-gnu-emacs@gnu.org>
2011-03-15 17:42                                 ` Stefan Monnier
     [not found]                               ` <mailman.3.1300204850.1264.help-gnu-emacs@gnu.org>
2011-03-15 17:49                                 ` Stefan Monnier
2011-03-15 18:56                                   ` Drew Adams
2011-03-15 21:30                                     ` Stefan Monnier
2011-03-15 19:02                                   ` Jason Earl
2011-03-15 20:55                                     ` Drew Adams
2011-03-16  4:31                                     ` rusi
2011-03-16  8:11                                       ` David Kastrup
2011-03-17  3:46                                         ` rusi
2011-03-17  7:10                                           ` rusi
2011-03-17  8:29                                             ` Antoine Levitt
     [not found]                                   ` <mailman.1.1300215374.6982.help-gnu-emacs@gnu.org>
2011-03-16 12:05                                     ` Uday S Reddy
2011-03-12 22:18             ` Tim X
2011-03-11 23:06         ` Uday Reddy
2011-03-10 22:40   ` David Kastrup
2011-03-11  2:46     ` Stefan Monnier
2011-04-01  3:20 ` rusi
2011-04-01 12:39   ` Uday Reddy
2011-03-02 17:12 Andreas Röhler
2011-03-03  4:58 ` Le Wang
     [not found] ` <mailman.7.1299128292.20537.help-gnu-emacs@gnu.org>
2011-03-13 15:05   ` Uday Reddy
  -- strict thread matches above, loose matches on Subject: below --
2009-12-20 19:19 Roland Winkler
2009-12-21 15:26 ` Stefan Monnier
2009-12-21 16:23   ` David Kastrup
2009-12-22 12:51     ` martin rudalics
2009-12-23  0:45     ` Stefan Monnier
2009-12-23  9:07       ` David Kastrup
2009-12-24  4:35         ` Stefan Monnier
2009-12-24  9:03           ` David Kastrup
2009-12-29 16:01             ` Stefan Monnier
2010-01-04  9:09               ` Drew Adams
2010-01-04 18:30                 ` Stefan Monnier
2010-01-05 20:17                   ` David Kastrup
2010-01-06  0:02                     ` Drew Adams
2010-01-06  4:20                       ` Stefan Monnier
2010-01-06  8:07                         ` David Kastrup
2010-01-06  8:57                           ` Drew Adams
2010-01-10  4:57                             ` Stefan Monnier
2010-01-10  8:12                               ` David Kastrup
2010-01-10 21:43                                 ` Stefan Monnier
2010-01-11  8:24                                   ` David Kastrup
2010-01-11  9:21                                     ` martin rudalics
2010-01-11 16:50                                       ` Stefan Monnier
2010-01-10 17:03                               ` Drew Adams
2010-01-10  4:51                           ` Stefan Monnier
2010-01-10 15:58                         ` Harald Hanche-Olsen
2010-01-10 18:05                           ` martin rudalics
2010-01-10 18:06                           ` Drew Adams
2010-01-10 19:44                             ` Harald Hanche-Olsen
2009-12-24 14:04   ` Roland Winkler
2010-01-04 17:08   ` Davis Herring
2010-01-04 17:34     ` David Kastrup
2010-01-04 18:33     ` Stefan Monnier
2009-12-18  9:20 Eli Zaretskii
2009-12-18 15:29 ` Juanma Barranquero
2009-12-18 15:58   ` Thierry Volpiatto

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=9F726D3B418A4DB6BF58058E2A8C880D@us.oracle.com \
    --to=drew.adams@oracle.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=uDOTsDOTreddy@cs.bham.ac.uk \
    /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.