On Fri, 26 Jul 2013 15:51:59 +0200, Sönke Ludwig wrote:

Am 26.07.2013 14:52, schrieb Manu Evans:

On Fri, 26 Jul 2013 12:12:11 GMT, Sönke Ludwig wrote:

You also have req.form.get("xyz", null) which does exactly that (see http://dlang.org/hash-map.html). Since this is standard D AA behavior, I didn't want to deviate from that potentially creating confusion.
Upon further consideration, I'm not sure I agree this is a good idea.
I tend to think web dev should be as friction-less as possible, and this is a rather pointless point of friction...
I can see where you're coming from, but I'm not sure I agree. Getting form/url args is a fundamental operation.

Perhaps it might be interesting if you supported opDispatch? I found myself even getting annoyed at having to type req.form["xyz"]. The whole [""] thing is unnatural to type quickly (at least for me), and it looks pretty noisy. 'req.form.xyz' would be pretty nice!

That would indeed be nice, but the question is which of the two is
usually desired?

string opDispatch(string field)() const {
    return m_aa.get(field, null);
}

or

string opDispatch(string field)() const {
    auto p = field in m_aa;
    enforceHTTP(p !is null, HTTPStatus.badRequest,
        "Request missing form field "~field);
    return *p;
}

If you asked me, I would say the former, since you can perform that enforce in the outer scope yourself if you like.
I guess I'm having a lot of trouble visualising how to write nice looking code with extensive use of exceptions.
If simple form handling logic is potentially throw-ing all over the place, what is the typical structure/flow to handle errors gracefully?
Are there any idiomatic examples of this sort of code?

I must confess, when I write C++, I always supply the compiler option to disable the exception handler ;)
I find comparing strings against null to be far simpler and more readable... but maybe that's just me.