News for hackers. Stuff that matters.
Re:Routing Enhancements for Go 1.22 by irq-1 on Tuesday February 13, 2024 @01:39PM (#39361098)
> What if two patterns overlap but neither is more specific? For example, /posts/{id} and /{resource}/latest both match /posts/latest. There is no obvious answer to which takes precedence, so we consider these patterns to conflict with each other. Registering both of them (in either order!) will panic.

A panic? That's a bad dev experience. Why not say an earlier variable is more general -- or a later variable is more specific? /posts/{id} wins.

Consider /posts/{id} vs:

    /posts/latest/{u}    // wins (later variable)
    /posts/{id}/latest   // wins (more specific)
    /posts/{id}/{id2}    // wins (later variable. id2 must exist)
    /{u}/posts/          // lose (earlier variable)
    /posts/{otherId}     // invalid (same path with different name)
    /latest/{u}          // no conflict
Re:Routing Enhancements for Go 1.22 by randomdata on Tuesday February 13, 2024 @03:57PM (#39362717)
> A panic?

Sure. That's precisely what exceptions (panics) are for: To deal with programmer mistakes identified at runtime that the compiler failed to detect. The use is appropriate.

If you want perfect compile-time safety, Go is not it. It prioritizes other tradeoffs. Such is engineering.

Re:Routing Enhancements for Go 1.22 by mhsred5 on Tuesday February 13, 2024 @03:09PM (#39362215)
Picking a winner in such a conflict leads to unexpected behavior if ordering changes.