Type-Safe Router - Design Discussion #15
Unanswered
dcrockwell
asked this question in
Q&A
Replies: 1 comment 3 replies
-
|
Catching things at compile time is super useful. Elixir does this a lot via macros. thus for 2: |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
@lpil raised an important point: Dream's router isn't type safe. Path parameters aren't encoded in types.
Change
/users/:idto/users/:user_idand your handler fails at runtime, not compile time.He's right.
We're trying to understand whether compile-time safety is worth redesigning the router API, and what approaches might be possible in Gleam.
Performance is solved
We've moved from linear search O(n routes) to a radix trie O(path depth). That part's done (PR coming today).
Benchmark results from testing radix trie router vs linear router:
Type safety is the question
The problem:
Path and controller aren't connected. Compiler can't help.
Type-safe routing would mean:
Current runtime approach:
route(method:, path:, controller:, middleware:)require_int(request, "id")Questions
1. Real-world experience
In frameworks you've used (Phoenix, Rails, Express, Django, etc.), do path parameter mismatches make it to production? Or do tests catch them first?
2. What would you trade for safety?
Would you accept:
3. Examples from other ecosystems
What type-safe routing have you used? What felt good? What was painful?
4. What's possible in Gleam?
Without macros or build-time codegen, what approaches could work? Are there patterns we're missing?
Share your thoughts
Your experience helps us understand whether this is worth the engineering cost, and what solutions might be possible.
Beta Was this translation helpful? Give feedback.
All reactions