-
-
Notifications
You must be signed in to change notification settings - Fork 34
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
Simpler description of the matching algorithm #715
Comments
This algorithm does not match exactly this part of our current solution: message-format-wg/spec/formatting.md Lines 488 to 489 in 07f6309
To demonstrate this, consider the message
Here, all three variants will match the selectors. The current algorithm will select My preference here would be to simplify the algorithm further, and to encode a preferential relation like "
|
I don't agree with your reasoning. What you're suggesting would reopen the old arguments that resulted in this design document. |
That's not what I meant. I meant that with first-choice selection, replicating our current behaviour would require the message to be expressed as
In all other programming and otherwise code-like languages that I regularly interact with, the switch and pattern-matching constructs select the first matching case. So to be honest, right now, the MF2 behaviour of not doing that is surprising.
Right now, yes, they might, because we have a really complex selection algorithm that's allowing for that transform to be really lazy. But adding a requirement on message migration tools to order the variants is not onerous. For plural selectors, I've now written implementations that do that in JavaScript and Python. The former is probably easier to read, and it's five lines of code.
Yes. And I brought this up because I observe in #706 (comment) and here that the solution we ended up with is sufficiently complex that we ourselves are not all sharing the same understanding of it. If it's not clear to us, it won't be clear to our users. |
Noting first that this discussion is post v45. That is, nothing discussed here should impede the progress of implementing the C++, Java, and Javascript tech preview implementations (having the spec jiggle around under the implementer's feet will do that). It is certainly far simpler to take first matching variant. And it is more likely that implementations will implement it the same way, and be interoperable. it is also faster at runtime. It does have implications:
|
And that is exactly what bothers me most! Note that we have custom selectors. Most tools will not reorder, and will not expand. Please, let's not open this can of worms! |
Best-match (vs. first-match) is a consensus discussion we had (at great length) previously (initially settled in the 2023-03-27 call). Many of the arguments being made here are already in the design document I quoted above. I'm open to considering changing the description of the algorithm, a la @macchiati's proposal. We should focus the discussion in this issue on that. The bar to re-opening consensus is higher and shouldn't be mixed with feedback on improving the current documentation. Please note that I am not saying that we don't want feedback on people's lived experience with the current matching algorithm. |
Duplicates #898. We're keeping the latter issue as it is more detailed. |
I think we can have a simpler exposition of the matching algorithm. Here is my take
Implementing the algorithm for matching requires two capabilities of functions. I think of these in terms of objects, but of course it can be done in a non-OO language.
Given a bound selector BS consisting of a value, a function, and a set of options, we need two operations.
Here is how the matching can be performed. Each variant has a list of keys plus a message.
Note: there are various further optimizations that can be done without changing the result. For example, it is possible to combine the two calls on matches and compare (but at the expense of complicating the algorithm a bit).
The text was updated successfully, but these errors were encountered: