Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] warn on second call to the dispatch function #30

Merged
merged 1 commit into from
May 29, 2024

Conversation

gasche
Copy link
Member

@gasche gasche commented Dec 25, 2015

It is an embarrassing shortcoming of the plugin-tags work that calling the dispatch function several times just silently overrides its behaviour. Forcing users to call dispatch exactly once may be the right interface to expose, but not saying anything if they make a mistake is bad usability.

One approach would be to keep a queue of hooks, push each new hook, and call them in order at dispatch time. I decided not to do that, however, because that would encourage an imperative way to provide functionality, with each plugin doing its own dispatch call; this would be fairly fragile as (1) users would have little control over the ordering on plugin rules and (2) they would have to jump through hoops to make sure the plugins are really linked, otherwise their effect would get silently dropped.

By forcing that there is at most one dispatch call, we in fact enforce a pure, declarative interface between plugin providers and plugin users. This has worked out rather well in practice (despite the subpar usability of the current code), see js_of_ocaml ocamlbuild plugin for example.

This PR keeps this current interface of having a single dispatch call, but adds a warning each time a previously installed hook is discarded. (The formatted warning text is rather painful to read, so I will probably convert it to one of Daniel's Bünzli nice formatting functions instead.)

src/hooks.ml Outdated
One@ should@ not@ setup@ hooks@ several@ times,@ but@ rather@ \
combine@ several@ dispatch@ functions@ explicitly@ \
in@ a@ single@ dispatch@ call.@ This@ lets@ you@ declare@ \
the@ horder@ between@ sub-hooks@ instead@ of@ relying@ \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

declare the border

@whitequark
Copy link
Member

@gasche I'd like to nominate this for inclusion in 0.11.

@gasche
Copy link
Member Author

gasche commented Feb 28, 2017

I rebased, used Format.pp_print_text (available since OCaml 4.02, we require 4.03 and above), and updated the warning message. Would you have any comment on the message? I would like to be not too confusing for beginners, and in particular indicate what has to be fixed.

Copy link
Member

@whitequark whitequark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@whitequark
Copy link
Member

@gasche can you rebase this on top of master, to trigger the build?

@hhugo
Copy link
Collaborator

hhugo commented May 29, 2024

Should we merge this one ?

@kit-ty-kate
Copy link
Member

Sounds reasonable. Let's

@kit-ty-kate kit-ty-kate merged commit 351c048 into ocaml:master May 29, 2024
@kit-ty-kate
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants