5 ms·
The problem with this approach is readability. If you look at the code vs Sinatra every time you want to figure out which route to edit, you have to traverse th
by UUMMUU 12y ago
The problem with this approach is readability. If you look at the code vs Sinatra every time you want to figure out which route to edit, you have to traverse the tree as opposed to just scanning for the route you want. As an example, editing the route /artist/:id/album/:number requires you to first find the /artist/:id then scan down and look for /album/:number making sure you watch for the closing end because what if the route isn't defined? In Sinatra, you look for /artist/:id/album/:number. The solution to this is to put a comment on every route to denote where it is. I agree the tree methodology can be faster O(log N) (for GET and POST) vs O(N) but readability suffers with no comments.
- sebkomianos 12y agoAnd it suffers even more if you add comments; for the same exact reason.
- noelwelsh 12y agoJust refactor your routes like you would any other code that has excessive nesting.
- zem 12y agoa fairly trivial fix would be to have routes optionally defined as "[/artist/:id/album]/number" where the [...] prefix is not required, but is checked for correctness if present.
- hamburglar 12y agoAgreed wholeheartedly, but have you ever tried to read Sequel code? I think massively over-clever code is this dude's thing.
- jeremyevans 12y agoThe basic design for Roda was taken from Cuba (it's a fork of Cuba), and I think if you read the Roda source, you wouldn't find it difficult to understand. There are certainly parts of Sequel that are overly clever, I won't argue that. But compared to similar libraries, I don't think it's worse in that department.
- hamburglar 12y agoFull disclosure: it's been years and major revisions since I looked at Sequel code, so my criticism may well be outdated.
- im_dario 12y agoI knew it felt familiar to me :) My first public side project was built with Cuba. Indeed, I contributed i18n to cuba-contrib around 2011 [0] Nice to see new ideas around web frameworks. Kudos! [0] https://github.com/imdario/cuba-contrib/commits/master https://github.com/imdario/cuba-contrib/commits/master
- im_dario 12y agoFew days later... I did my own routing tree in Go https://github.com/imdario/medeina https://github.com/imdario/medeina Thanks for the inspiration!
- ehm_may 12y agoWhy couldn't Sinatra create some sort of underlying tree structure that could perform in O(log N) as opposed to O(N). That way you get the readability with the perf.
- vidarh 12y agoIt couldn't create a tree in all instances because it allows full regexes in the routes. It could create a hybrid (split into trees for anything with a known static prefix), or go the full hog to a finite automata, though. But at least the latter is suddenly a big complexity increase.
- mahmoudimus 12y agoI actually attempted at taking a stab to this problem for Python's Pyramid framework when using Pyramid's traversal algorithm for routes. It's not cleaned up yet, but here is the link: https://github.com/mahmoudimus/pyramid_maze https://github.com/mahmoudimus/pyramid_maze