Why the most specific pattern wins
The two rules that decide every match, why they give one answer for every query, and what the alphabetical order costs.
patrun answers a query by two rules and nothing else. The first: a pattern that matches more of the query's properties beats one that matches fewer. The second: between patterns that match as many, the properties are compared one by one, with their keys in a fixed order, alphabetical unless the router names keys to come first. The first property where the two differ decides: by its key, or, at the same key, by its value, where an exact value beats '*'.
Why more properties win #
The first rule is what lets special cases sit beside the general ones. A pattern for books in Ireland has one more property than the pattern for Ireland, so a sale of books gets its own rate and every other sale in Ireland still gets the general one. Nobody has to order the rules by hand, and nobody has to remember that the special case must come before the general one, as an if ladder needs.
The rule also means that a pattern which adds properties to another always wins over it. Every query that matches it also matches the other, which makes it a special case of the other, and the special case should win.
Why a fixed order of keys #
The first rule leaves ties: two patterns can match a query with as many properties each, with neither a special case of the other. { a: 1 } and { b: 2 } both match { a: 1, b: 2 }. Something has to decide, and patrun decides by the properties, with their keys in a fixed order.
The order of adding would decide too, but then a router's answers would depend on how the code that built it ran: on the order modules loaded, or plugins registered. With a fixed order of keys, a router's answers depend on its patterns alone. add({ a: 1, b: 2 }) and add({ b: 2, a: 1 }) build the same tree, and two routers that hold the same patterns give the same answers.
Together the two rules put the patterns that match a query in one order with no ties, so find has exactly one answer. How a match is chosen states the order in full, and the definition proves it has no ties.
What it costs #
The alphabetical order is arbitrary. That a comes before b says nothing about which property matters more to the program, so a tie can be settled the wrong way for a particular query. There are two ways out. The order option names the keys that matter more, and they then decide first. Or a pattern for the two properties together, which has more properties, settles that query outright. The rules never guess: where they decide something the program cares about, the program says so with a pattern.
Why not a chain of if statements #
A handful of cases is fine as if statements. Once there are sub-cases and sub-sub-cases, the ladder of if statements is hard to read, and every new case means finding the right place in it. Two people adding cases at once both change the same branch. A router lets each case be added, removed, listed, and inspected on its own, and the rules above put it in its place.