Remove 'route' and 'nested_route' macro and add route inference to the generator #789
-
Current implementation is tricky to understand and documentThe current implementation ( However, Move inference to generatorsI think the way to get the best of all worlds is to build the inference in to the generator. Examples: *.
If you don't use a RESTful resource (like
|
Beta Was this translation helpful? Give feedback.
Replies: 23 comments 1 reply
-
I think this will be a great use to test out adding the examples to the generator. Once you start adding several arguments to a task, knowing the order, and how they should be formatted can get confusing. Things I like about this
Things I will miss
I think it's a decent trade-off. |
Beta Was this translation helpful? Give feedback.
-
I'm a bit on the fence for this as I tend not to use generators in general (except when required like when initializing projects or creating new migrations)...it also does less to discourage less RESTful routes as it's not baked into the syntax. If the issue is the additional confusion, one could add a comment above the In summary, it's probably the right move if lots of people are getting confused but I'm a bit weary regardless |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Yes, that's convicing. In the end it's better to have the route written down explicitly. |
Beta Was this translation helpful? Give feedback.
-
I think |
Beta Was this translation helpful? Give feedback.
-
@wontruefree i think if we add route generation to the generators the speed will be the same as using route/nested_route but I’d love to hear more about what you think. What else is slow about Lucky? I’d love to make Lucky a great dev experience for prototyping. I feel that it is but since I wrote it I understand some of the trickier parts and so it is hard to see what is stumping people. Nested resources are definitely tricky and I think they’re a bit tricky in any framework at first. I can’t think of a way to do a generator for nested resources since it would need to know if the parent is already created or not and a bunch of other stuff. So I wonder if we just need to document it better with full examples? |
Beta Was this translation helpful? Give feedback.
-
@HarrisonB i just saw your message. I like the idea of commenting. I’ll have to think about that. I think that another issue is with requiring a module namespace for nested routes. It adds a decent amount of typing and confusion for new people so not sure how to address that. I’ll try to think about it more. Maybe there is a middle ground... |
Beta Was this translation helpful? Give feedback.
-
Maybe |
Beta Was this translation helpful? Give feedback.
-
My $0.02 😄 I would like to just switch to 100% explicit routes. It seems unnecessary to have multiple ways to do this when one gives the same functionality with added documentation. It also seems like it is more in line with crystal’s philosophy (https://github.com/crystal-lang/crystal/wiki/FAQ#why-dont-you-add-syntax-for-xyz) I think having multiple ways to do things when one is sufficient compounded over time can make a framework harder/easier to learn and use. I think we will all appreciate it down the road when someone asks “how do you make an action/route” and there is one simple answer. |
Beta Was this translation helpful? Give feedback.
-
@bdtomlin that makes a lot of sense. I am leaning I think I’m going to try this on some projects and see how it goes. Would love to hear what people think after trying it out |
Beta Was this translation helpful? Give feedback.
-
@paulcsmith I currently just have one project in Lucky. I have used route and nested route everywhere. I will convert it to explicit routes and use them going forward in the name of science 😁 I will let you know my obviously biased opinion when I’m done converting. I usually only use generators for models and migrations though, so I might not be much help in that area. |
Beta Was this translation helpful? Give feedback.
-
Thanks @bdtomlin. Looking forward to hearing what you think :) @jwoertink what is your team using? Is it mostly route/nested_route? |
Beta Was this translation helpful? Give feedback.
-
We only use explicit routes, even on our restful actions. So we don't have any route or nested_route helpers. |
Beta Was this translation helpful? Give feedback.
-
FWIW, I prefer explicit routes. It's just a bit more to write but so much clearer. |
Beta Was this translation helpful? Give feedback.
-
@wout I kind of agree. I spend more time thinking about what the inferred path is and what the param name is than I would just writing out the path and reading it. Gonna try it out a bit more first and see what others think after trying it, but so far it seems this will be a good way to go |
Beta Was this translation helpful? Give feedback.
-
Also of note is that we can remove the parent resource namespace requirement for nested route. For example: # Need the `Repositories` so `nested_route` knows what the parent is
class Repositories::Issues::Show < BrowserAction
nested_route do
end
end
# No longer need the unnecessary (and often confusing) namespace
class Issues::Show < BrowserAction
get "/repositories/:repo_id/issues/:issue_id" do
end
end This is more in line with what you typically see in Rails and other web frameworks and removes some gotchas that can come up where you've got some actions nested and some without EDIT: Also it is shorter to link to! |
Beta Was this translation helpful? Give feedback.
-
I've converted all of my actions to explicit routes and here are my takeaways:
Conclusion I will be using explicit paths on my projects going forward. I really like the clarity and everything I learned through this process was a positive for explicit routes. |
Beta Was this translation helpful? Give feedback.
-
Thank you for sharing your in put @bdtomlin. That was very thorough and helpful. The slash requirement was added for consistency. We'd have to add more tests/code to add a slash if one doesn't exist, and I like the idea of having one way to do something. The reason for a slash and not no-slash is that then you'd have weird routes like this: |
Beta Was this translation helpful? Give feedback.
-
Also one worry I have with explicit routes (but also applies to the route macro!) is that you may have small inconsistencies like |
Beta Was this translation helpful? Give feedback.
-
@paulcsmith I understand on the slash. It kind of helps to serve as documentation saying "this is a route". I definitely prefer having one way to do things where possible as well. I definitely think this should be kept as is after hearing your thoughts and thinking about it a little. I think a consistency check would be really nice, maybe it should be ran manually like |
Beta Was this translation helpful? Give feedback.
-
@bdtomlin Yes good point! I think definitely a manual task that you could run as you-go or in CI if you want to automate it. And I think it should have a yaml file for ignoring certain routes if you meant for them to be slightly different so that you can fail CI for inconsistent routes, but have it pass by manually ignoring them in the yaml file. |
Beta Was this translation helpful? Give feedback.
-
I think we can close this discussion and I'll make an issue. Here is what I think we should do: Generator changes
Other
Keeping things clean and consistent
Moving forwardI plan to break these out into different issues so it isn't too overwhelming to work on. I feel good about this, but if someone has any major concerns, LMK and we can see if we can improve this! If you like this, feel free to 👍 or comment |
Beta Was this translation helpful? Give feedback.
-
Just posted a new milestone with issues for switching this over. If you'd like to help, please comment before starting to make sure myself or someone else hasn't started already Thanks for all the input! |
Beta Was this translation helpful? Give feedback.
I think we can close this discussion and I'll make an issue. Here is what I think we should do:
Generator changes
lucky gen.action.browser Users::Show
will generate an action and will set path toget "/users/:user_id"
."/projects/:project_id/users/:user_id"
-n
or--nested
option where you can set a parent from the generator:lucky gen.action.brows…