Back when I started to program, all my programs where something like this:
It didn’t took me long for that to become:
Those were the days. Developing interactive programs wasn’t that hard. Nowadays, developing interactive program for me is something along these lines:
Remeber that I omitted all the code related to saving and loading state, which could actually be tricky. I’m aware that there are other options out there, for example using
needjs, the code will turn to this:
Which is easier, but also a lot wordier, and now I have to worry about needs and their dependency systems.
What I’m trying to say is, these days trying to write stateful programs that interact with users(more than one) specially when there are more than one users, is really hard.
So I was thinking, how can I change this?
I want to write programs that look like this:
And basically this should be converted into something like this:
And of course the State would be a special async function that doesn’t run the same code for the same session more than once.
You might ask, doesn’t this look more complicated? How should I write that?
Well, I’m hoping to use
babel or something similiar in order to transform the code without the programmer having to write the complicated stuff.
However, there are a few challenges that I have to face.
Making the code work inside loops is a challenge that I’m still thinking about. There are different ways to implement a loop proof system, however, I’m not sure which would be better.
The stateful function should ‘resume’ upon server restart.
If the programmer changes the code and then restart the server… well, there are tons of different things that could be done in these scenarios. Perhaps one could implement a pluggable system, however in order to keep things simple it should put convention over configuration, meaning the programmer should not have to config everything, but if she wants to change how something works, she should be able to.
There might be many, many different types of challenges that I’m not thinking about at the moment. If you can think of one, and have solution for it, please don’t forget to drop a comment here! You’ll need a Github account.