A Better Example of Command-Query Separation

Daneel3001 just posted this little quartet on Twitter:

@udidahan decisions. And I guess the command will either succeed, or fail by raising a compensating action (booking couldn't succeed).

@udidahan Yet, there are some cases where the command will not enable the domain, cinema room here, won't have the freedom to make much.

@udidahan You were rightly stating that grid like views of data as having negative effect on understanding intent of user actions.

@udidahan Maybe instead of using the hotel booking analogy for explaining CQS you could have used the cinema seat booking.

- and that reminded me of one of my all-time frustrations with the internet – booking theatre tickets – which, coincidentally, dovetails very neatly with something Udi Dahan was describing last night.

I work in Leicester Square. I walk past a dozen theatres every day, so if I want to see a show, it really doesn’t matter when I go and see it. I can go any time – and yet, every single theatre and ticket website starts the search process by saying “which day do you want to go?” – and then this happens:

Me: Friday.
Computer: Sorry, sold out.
Me: OK, Wednesday.
Computer: Sorry, sold out.
Me: OK, Tuesday.
Computer: Great! Tuesday! We can do that! Now, choose a seating section:
Me: Dress Circle, please.
Computer: Sorry – sold out.

What I really want is a to be able to say “I want to see Mamma Mia. I want to sit anywhere in the front ten rows, anytime between now and Christmas, and I can’t make Sep 23rd or any Saturday” – and, as Udi put it, let the computer do the busy-work. I know that the data is in there. I know that there are algorithms capable of fulfilling that request. Why the hell am I sitting here brute-forcing a solution and whacking the back button like I’m playing Track & Field 2 all over again?

Most current ticket-booking websites will reduce your request to “seats H24, H25, H26 and H27 for Chicago at 19:00 on Saturday 25th” – but that request is just too detailed, and far too prone to failure, and doesn’t reflect AT ALL what I’m actually trying to achieve. Maybe I’m only in town for Saturday night and don’t care what show I see. Maybe I desperately want to see Chicago but I’m prepared to go on any night. Maybe I’d be happy with two pairs of tickets instead of four together. I’d love a website that actually asked me what I wanted on my terms instead of presenting me with a bunch of data and expecting me to do the grunt work.

Command-query separation would appear to be the first step towards this – but it seems that what’s really important here is that your command model reflects the intention of your users, rather than the shape of your data.