unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Daniel Nagy <danielnagy@posteo.de>
Cc: 66890@debbugs.gnu.org
Subject: bug#66890: 29.1; buffer-size should also accept the buffer's name as string argument
Date: Sun, 05 Nov 2023 18:02:03 -0500	[thread overview]
Message-ID: <jwvwmuv6dtq.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <87jzqxgrof.fsf@posteo.de> (Daniel Nagy's message of "Sat, 04 Nov 2023 20:57:41 +0000")

>> The reason is that I've seen several ELisp packages which abused
>> buffer names as "handles" for buffers, leading to nasty bugs when
>> those buffers get renamed (e.g. by things like uniquify).
> A reduced API surface will not prevent people from using buffer names as
> handles.

Indeed.  But the extra annoyance of having to use `get-buffer`
everywhere may push them to try and store the result of that
`get-buffer` somewhere.  It wouldn't eliminate the problem, but it would
have made it less common, I believe.  Not like it matters, tho.

[ When I look at all the programming languages out there, and how they
  are fundamentally almost all identical except for "cosmetic details"
  here and there, and the sometimes wildly different coding styles that
  come out of them, I end up with the conviction that those "cosmetic
  details" are what drives the coding styles.  :-)  ]

>> Could you show some examples of the kind of reductions you're thinking
>> of?
> No, I cannot. This was mostly meant as a general statement. But maybe I
> can argue in the other direction. What if things from that list above
> were requiring to be more explicit. Such that you would need to write
> `(with-current-buffer (get-buffer "mybuffer") ...)' instead of
> `(with-current-buffer "mybuffer" ...)'.

Oh, thanks.  Yes, these are very much the kinds of examples of
reductions I asked.  And indeed `grep` suggests we have quite some
number of those; and by now, you can guess that I see those as latent
bugs (aka "code smells")  :-(
Maybe we should add a compiler warning for that :-)

> In general, I would say that, if the computer can unambigously decide
> what is supposed to happen, it should help me and automatically correct
> my "mistakes".

I'm a big fan of that, also.  But indeed, while using a string as
"buffer" for one-off code in `M-:` would be handy, refusing it in "real"
ELisp code would help the programmer avoid that mistake :-)

> Also I would argue, that is similar to what is already
> present in Emacs with the dwim commands.

Indeed, commands are like `M-:`, so we like to have them "guess the
right thing" for us.  But note that we have DWIM commands but not DWIM
functions, because code needs to work right in "all" cases rather just
in the current specific circumstance, so it's much easier to write code
using functions that do just one thing only than using DWIM functions
which can do all kinds of different operations depending on
the circumstances.

> Commands can behave differently if, for example a region is active. So
> the "Do what I mean" notion means, if I pass in a string, does the
> function unambigously know what I mean with that?  If yes, then it
> should do that.

That can be handy, but encourages bad coding practices, so when we do
accept it we usually like to emit a warning.  Especially since most
ELisp programmers are far from experts at ELisp.  So we need to try and
help them avoid pitfalls.

Most buffers never change name, so it's easy for the occasional ELisp
programmer to think of the name as being just as good as the buffer
itself.  But their code will break down when it gets run in someone
else's setup where some local customization dynamically renames all
buffers to use a particular naming scheme.


        Stefan






  parent reply	other threads:[~2023-11-05 23:02 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-01 16:31 bug#66890: 29.1; buffer-size should also accept the buffer's name as string argument Daniel Nagy
2023-11-02  6:32 ` Eli Zaretskii
2023-11-02 19:38   ` Stefan Kangas
2023-11-02 20:55     ` Daniel Nagy
2023-11-03 13:38       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-04  0:21         ` Stefan Kangas
2023-11-04  6:03           ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-04 10:43             ` Stefan Kangas
2023-11-04 20:57         ` Daniel Nagy
2023-11-04 22:12           ` Drew Adams
2023-11-05  5:35           ` Eli Zaretskii
2023-11-05 23:02           ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
     [not found]     ` <87bkcbzy6c.fsf@posteo.de>
2023-11-03  6:46       ` Eli Zaretskii

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=jwvwmuv6dtq.fsf-monnier+emacs@gnu.org \
    --to=bug-gnu-emacs@gnu.org \
    --cc=66890@debbugs.gnu.org \
    --cc=danielnagy@posteo.de \
    --cc=monnier@iro.umontreal.ca \
    /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).