Python Forum
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Mini-Web Framework
#2
For more info on why I wanted to try routing via annotations, let's start with what other frameworks/languages do, and why I think most of them are bad.

In the beginning, there was php/perl, where your urls were decided by your file names. If you later want to refactor your code, you need to leave "stub" files with the original file names that do nothing but call the new files, so old bookmarks to your site continue to work. That's terrible.

Then people started using frameworks. Cakephp, CodeIgniter, Ruby on Rails, Asp.net and many others all follow the same pattern. Which is to say, your urls are decided for you based on your class/method names. Which, again, makes refactoring your code difficult, if not just completely infeasible.

Django, I feel, was a good step in the right direction. By having all the urls defined in a urls.py file, which then mapped to whatever end point you wanted to handle that url, you could change the underlying application at any time, without fear of breaking any urls. The only problem, was that the urls were defined in urls.py... so far away from the controller (they call it a view) which handles that url. In the real world, you link pages together with page navigation, so knowing what the url is actually matters, and should be easily identifiable for a particular controller.

Which is why I like Flask. The url is detached from the file structure, while still being physically close to the method which actually handles the request, so writing the view is easy since you can easily see which urls go where.

But Flask uses a decorator to apply the routing. I view a controller's url as little more than metadata for that controller, so wrapping the endpoint in a decorator feels like using a sledge hammer where a rubber mallet is much more suitable. Things that mutate the controller, should be things that actually mutate the in/output, not things that just keep track of metadata. Before annotations were added, however, decorators were the cleanest way to handle it.

But now we have annotations. So now I wanted to try to utilize them, to show semantic meaning to the site I'm building. So far, I think it doesn't look that bad.
Reply


Messages In This Thread
Mini-Web Framework - by nilamo - May-25-2017, 03:34 AM
RE: Mini-Web Framework - by nilamo - May-25-2017, 03:28 PM
RE: Mini-Web Framework - by wavic - May-25-2017, 04:05 PM
RE: Mini-Web Framework - by nilamo - May-25-2017, 05:05 PM
RE: Mini-Web Framework - by micseydel - May-25-2017, 08:55 PM
RE: Mini-Web Framework - by nilamo - May-25-2017, 09:19 PM
RE: Mini-Web Framework - by nilamo - Jun-06-2017, 01:23 AM
RE: Mini-Web Framework - by wavic - Jun-06-2017, 03:32 AM
RE: Mini-Web Framework - by nilamo - Jun-06-2017, 03:42 PM
RE: Mini-Web Framework - by wavic - Jun-06-2017, 05:00 PM
RE: Mini-Web Framework - by Skaperen - Jun-14-2017, 06:19 AM
RE: Mini-Web Framework - by nilamo - Jun-14-2017, 11:16 PM
RE: Mini-Web Framework - by Skaperen - Jun-15-2017, 05:32 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Guess the dice roll mini-game tawnnx 6 7,444 May-22-2018, 02:12 PM
Last Post: malonn
  5 mini programming projects for the python beginner kerzol81 4 36,315 Sep-26-2017, 02:36 PM
Last Post: VeenaReddy

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020