unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "Paul W. Rankin" via "Emacs development discussions." <emacs-devel@gnu.org>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: emacs-devel@gnu.org
Subject: Re: declare function/macro private
Date: Mon, 7 Jun 2021 10:59:16 +1000	[thread overview]
Message-ID: <7D467006-748F-4316-939E-C82D62D80221@bydasein.com> (raw)
In-Reply-To: <jwvwnr6swka.fsf-monnier+emacs@gnu.org>



> On 7 Jun 2021, at 4:05 am, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
> 
>> Of course there's already the convention of prefix--my-private-function, but
> 
> What would be the difference between this convention and your proposed declaration?

Stefan, you must have missed my followup reply:

..that would be great if a function declared as internal appears outside of its program then it gets highlighted in font-lock-warning-face. Then the curious programmer calls `C-h f' on it and the help buffer could show e.g.

 This function is internal to <library> and should not be used
 in other lisp programs. Use <other-function> instead.

The "--" convention is fine and I wouldn't suggest to change/replace this; it's clear to people what it means once they've learnt what the convention means.

I think requiring a program to explicitly declare something as internal will cause less trouble than adding a kind of compiler heuristic for "--" symbol names because there are likely plenty of those where people have used the name with the perspective that it's just a hint and doesn't actually do anything. e.g. `imenu--index-alist' is supposedly internal but any elisp program hooking into Imenu needs to use this variable.

Also I just dislike computer heuristics.

I'll revise the initial suggestion from `private' to `internal' since that's more the Emacs lexicon, i.e.

 (declare (internal t))
 (declare (internal "use `other-function' instead."))


>> my thinking here is that a program could declare a function/macro as
>> private, then the compiler could signal a warning/error if that function
>> appeared in a library outside the library it was defined and
>> declared private.
> 
> We don't have a definition for "library", sadly.

M-x find library says otherwise. But the definition of a "library" is inconsequential. Using "file" might be more helpful.

> I think the "--" convention actually includes an extra information
> compared to yours which could be useful here: we could warn for uses of
> "foo--" if and only if the use appears in something whose name doesn't
> start with "foo-".
> 

> IOW, use the string before the "--" as the definition of the "library"
> (so that would support cases where a library is spread over several
> files, as well as the case where a single file contains "internal
> libraries").
> 
> Of course, if we enable such a warning now, we'll get a fairly large
> number of warnings, I think ;-)
> 
> Another advantage of the "--" convention is that you don't need to load
> the definition of that function in order to discover that it's private.

I'm not suggesting to do away with using "--" as a handy visual marker. I use that too.

I would caution that trying to introduce a heuristic approach to interpret human intent from just "--" in a symbol name is the path to ruin.

As for the case of "libraries" over separate files, again it's probably best to use the word "file" instead of "library" to define the limits of the suggestion; consider declare-function as corollary:

  Tell the byte-compiler that function FN is defined, in FILE.

And `(declare (internal t))' would be:

  Tell the byte-compile that this function is internal to this file.









  parent reply	other threads:[~2021-06-07  0:59 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-06  4:27 declare function/macro private Paul W. Rankin via Emacs development discussions.
2021-06-06  7:09 ` Omar Polo
2021-06-06  7:18   ` Paul W. Rankin via Emacs development discussions.
2021-06-06  9:53 ` Lars Ingebrigtsen
2021-06-06 12:43   ` Paul W. Rankin via Emacs development discussions.
2021-06-08  9:43     ` Lars Ingebrigtsen
2021-06-08 17:26       ` Robin Tarsiger
2021-06-06 18:05 ` Stefan Monnier
2021-06-06 18:12   ` Tassilo Horn
2021-06-06 20:12     ` Stefan Monnier
2021-06-07  0:51       ` Paul W. Rankin via Emacs development discussions.
2021-06-07  1:37         ` Arthur Miller
2021-06-07  1:43           ` Paul W. Rankin via Emacs development discussions.
2021-06-07 13:38             ` Arthur Miller
2021-06-07  0:59   ` Paul W. Rankin via Emacs development discussions. [this message]
2021-06-07  2:54     ` Stefan Monnier
2021-06-07 18:24       ` Arthur Miller
  -- strict thread matches above, loose matches on Subject: below --
2021-06-07  3:35 Boruch Baum
2021-06-07  4:49 ` Paul W. Rankin via Emacs development discussions.
2021-06-07  5:59   ` Stefan Monnier
2021-06-07  6:45     ` Paul W. Rankin via Emacs development discussions.
2021-06-07 12:39 ` Eli Zaretskii
2021-06-08  1:14   ` Boruch Baum
2021-06-08  4:20     ` Arthur Miller
2021-06-08  5:49       ` tomas
2021-06-08 15:46     ` Stefan Monnier

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=7D467006-748F-4316-939E-C82D62D80221@bydasein.com \
    --to=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=pwr@bydasein.com \
    /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).