by irq-1 · 2y ago · 0 comments
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 conflictSure. 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.