Previous Entry Share Next Entry
Work is no respecter of sleep
jducoeur wrote in querki_project
[This one's not *too* technical, but the programmers will understand why I'm kicking myself this morning.]

The first serious Querki application is our Wedding RSVP system -- now that I'm done moving, I'm finally working on that full-time again. It's useful to have something practical, to show me where the seams are in the design.

For example, there's the problem of email invitations. I have a model called Person -- the public concept of a person in Querki -- which I've subclassed as Invitee for purposes of this app. And I have a model called Email Message, which lets you define a template for sending out emails. The Email Message has the properties you would expect, such as Subject and Body, and an Email To list of Persons to send it to. When you tell it to send, it fills in the template exactly the way we normally do for displaying a Thing as a page, but using the Person you are sending to as the context, so you can easily customize emails per-person.

(Tangent: this is the direction I'm leaning for email in Querki. Email's a *very* dangerous topic, because of course I don't want Querki to be used for spam. So email is going to be relatively expensive -- free accounts are only allowed to send small numbers of emails, and even paid ones can't send tons of them. But to make up for that, the platform is going to make it trivially easy to mass-customize the emails you do send. This should make it very nice for club and SOHO uses.)

But the thing is -- I don't *want* to list all of those Email To's explicitly. Why would I? What I actually want is to send it to [[Invitee.all]] -- that is, all of the Invitees that I have entered. So I've been planning on adding an alternate Recipients property, which should be a *function* (that is, a QL expression) that returns a list of Persons. The email gets sent to either the explicit Email To list or the results of the Recipients function, depending on which one is specified. But that's been bugging me, because it feels like a hack.

Of course, it was 5am when my subconscious finally had its "Duh" moment. Getting back to sleep wasn't an option.

I've been thinking about this wrong. This isn't a special case at all -- it's just an illustration of what really should be a common principle throughout the system. You should be able to specify QL for *any* Property's value. There is exactly one exception -- the Name property really needs to be static for a variety of reasons -- but in all other cases we should be able to handle a given value or a function equally.

The reason why this is a "duh" illustrates one of the things that makes Querki interesting: the fact that it is *both* a database and an object-oriented programming language, intimately intertwined. As a database, this question looks a bit arcane -- this notion of being able to stick a function in place of data is essentially computed columns, which are a somewhat unusual feature. And you can pretty much never do this sort of substitution in an ad-hoc way in a database.

But when you think of Querki as an OO language, it's completely obvious: good modern OO languages *always* define properties so that constants, simple fields and functions look the same from the outside. And that's for exactly reasons like this -- that sometimes you just want to put in the data, and sometimes you want to define it in terms of something else.

This is going to be a bit of a pain in my ass because I only thought of it now; I'm going to have to go rewrite a lot of code to make this work nice and generally. It'll have to wait until after the wedding invites are out, using my original hack. But it's clearly correct, and it suddenly makes a lot of messy problems trivially easy. It's an advanced feature, aimed at the app-writers more than the typical end user, but I think the programmers in the crowd will find it both intuitive and powerful.

So, subconscious -- points for *eventually* coming up with the right solution. Next time, though, I'd prefer if you did so when I'm in the shower, okay?
Tags: ,


Log in

No account? Create an account