[Opa] a few crazy thoughts about client-server distribution

Owen Gunden ogunden at phauna.org
Sun Jan 29 22:16:17 UTC 2012


Opa is awesome. It lets me do much more than I would even consider
with other languages.

With new awesomeness, the door is open to new kinds of troubles. Like
how, when I'm not busy adding sexy features:

 I spend lots of time nudging the slicer to make sure my client-server
communication is fully optimized.

To be clear, if I didn't have the power of Opa, I never would have to
deal with this sort of thing because I wouldn't even attempt to do so
much ninja-action.

At any rate, I do try ninja-action and I make a lot of noob mistakes.
Like having a function that's intended to be client-only (e.g. an
oninput handler) that ends up making server calls. For example:

@client my_oninput_handler(_evt, field) =
    match option_of_string(Dom.get_value(#{field.id})) with
    | {none} -> Dom.hide(#{field.display_id})
    | {some=s} ->
        s = field.transform_for_display(s)
        do Dom.transform([#{field.display_id} <- s])
        Dom.show(#{field.display_id})

After noticing some slowness while typing into a field with this as
[oninput] handler, I added some printlns to determine that
field.transform_for_display was in fact being run on the server. Maybe
the slicer chose to put it there because the [field] record was
constructed on the server (I think it had to be because it contains
also a function which does some db access). At any rate, a simple
@client in the right spot made all the difference.

Crazy idea #1: It would be awesome if there were a directive
@client_only that would cause an error if my function ever calls
something on the server. Even awesomer if there were a way to make
exceptions to the rule; so that whenever I want to call something on
the server I have to say so.

Crazy idea #2: Generally I'm noticing paranoia about crossing the
client-server boundary is moderately healthy. So the idea is that
anytime you cross the client-server boundary (in either direction),
you have to annotate the call-site with something (e.g.
@call_on_server, @call_on_client). Perhaps they could be optional and
implemented as an optional compiler warning?

I'm still pretty new to this, though, so I could be way off the mark.
Feel free to tell me why these don't make sense :).


More information about the Opa mailing list