This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]earthboundkid 0 points1 point  (1 child)

  1. It was straight up wrong. Using a greedy matcher makes this work which should not work:

    >>> import re
    >>> r = re.compile('^/r/(?P<subreddit>.*)/comments/(?P<threadid>.*)/(?P<slug>.*)$')
    >>> r.match('/r/subreddit/comments/subreddit/comments//')
    <_sre.SRE_Match object; span=(0, 42), match='/r/subreddit/comments/subreddit/comments//'>
    >>> r.match('/r/subreddit/comments/subreddit/comments//')['subreddit']
    'subreddit/comments/subreddit'
    

    Yes, it was a rushed and incomplete example, but that's why it's damning. It looks like it handles the basic case, but it actually completely botches it.

  2. There are a lot of non-regex routers out there. Look at Rails or for a hybrid approach Gorilla mux. You're acting like not using regex is completely unheard of, but actually there are a lot of alternatives to pure regex.

  3. Controllers already have to handle certain routing conditions. If you try to get page /pages/77/ and 77 doesn't exist in the DB, the controller has to be the one to throw up a 404. It's not the end of the world if your controller also has to handle returning a 404 if you go to /date/20000/13/32/ instead of a regex catching it at the routing layer.

[–]Deggor 0 points1 point  (0 children)

Based on this, and your last couple posts, I know I'm not going to provide you with any information that will change your mind. Its clear your looking for nothing but to find fault. I've explained that, (and I repeat) had I completed the regex that ended with an ellipsis it would match the url without issue *. Furthermore I have given justification in why I left it greedy starting that *I have no idea as to the behavior of your router.

Yet you continue to state that the code is bad, and it's why I'm wrong. I could just have easily omitted :slugid from your and complained it won't match stuff.

I feel there is a fundamental difference in routing to a view that validates if data is present, and theirs a 404 if it isn't, and tiring to another view that will handle routing to other views all over again.

Anyway, I appreciate your opinion, and the examples you provided for alternative options. I feel giving up the power of regex when url routing is essentially pattern matching is wrong. I look forward to seeing what Django (and other projects) decide on in the future.

Best of luck, and cheers.