Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Dispatching With "with" (sigusr2.net)
9 points by apgwoz on March 4, 2009 | hide | past | favorite | 6 comments


So basically you're just faking blocks?


I guess to some degree, yes. It wouldn't be necessary to do any of this of course if Python had a multi-line lambda, since you could instead just say:

   app.get('/', lambda req: whatever)
Though, now that I think about it, I guess there's no reason not to just do:

    def something(request): pass
    app.get('/', something)
or better still

    @app.get('/')
    def something(request): pass
I just thought using 'with' was an interesting hack.


I just thought using 'with' was an interesting hack.

Sorry if I sounded a little harsh; it is an intersting hack and I really appreciate that you shared it with us. In fact, I love hacking around with languages (okay, it's mostly Ruby) and do weird/cool things.


Oh, I didn't take it as being harsh. It just made me realize, that despite it being interesting, the only thing it really adds is "coolness"


This is interesting. I have been using django for a while and work on a custom framework that barrows ideas, not code, from it's URL dispatch. I haven't really liked specifying and carrying around a list of regular expressions some place. This has given me new ideas.


My work-in-progress Python web framework called Webify (http://github.com/jperla/webify/tree/master) uses decorators for URL dispatching. It's definitely way better than a separate config of tuples.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: