These are chat archives for jdubray/sam

27th
Jan 2017
Rodrigo Carranza
@DrecDroid
Jan 27 2017 00:00
Is V really neccessary? or just for frontend?
Jean-Jacques Dubray
@jdubray
Jan 27 2017 00:00
I don't like as much
But maybe that's a personal preference
I'd like to keep the State representation and next-action predicate separate
conceptually you are correct, no question about it.
I feel that distributed systems need a "state representation" in their programming model
The state representation can be queried at any time, what is the current state (representation)?
So I would say V/State representation is necessary (in distributed systems).
Rodrigo Carranza
@DrecDroid
Jan 27 2017 00:05
system = S(nap1, nap2, nap3, ... , napk) where nap = f(Model.present(A(data)), then View could be written as V = repr(vm(Model.present(A(data))) and be one of the naps of the system.
Thats what I understand so far
I'm not mathematician Btw I'm just trying to express more formally but I don't have that knownledge to express It.
Jean-Jacques Dubray
@jdubray
Jan 27 2017 00:07
That's a possible implementation, I just don't like it as much, but again, that's more a preference.
Me neither, ... it's just that it felt right to express the pattern that way to show how simple and elegant it is (IMHO, and again it's all coming from TLA+).
Jean-Jacques Dubray
@jdubray
Jan 27 2017 00:14
TLA+ itself it not too clear about it, Dr. Lamport uses the concept of "pc" (program counter) to reference the "status" of the system.
Artyom Shalkhakov
@ashalkhakov
Jan 27 2017 01:13
Re: NAP. I've refactored the Tetris example a bit, with an explicit nap. Ticking should be decoupled from user input for games. I used a boolean value to exclude nap in cases when user input is handled.
Rodrigo Carranza
@DrecDroid
Jan 27 2017 01:23

For the lib I'm writing I would write It like

function timedAction (step){
  return function automaticAction(propose){
    var timer = setInterval(function(){ propose({timerEvent: true, timer }) }, step);
    return {
      stop: ()=>{
         clearInterval(timer);
         propose({
            stop: timer,
         }
      }
    }
  } 
}

system.registerActions(timedAction(100))

Something like that, just an idea

Jean-Jacques Dubray
@jdubray
Jan 27 2017 01:26
@DrecDroid That's a bit different, I believe this is more like an event (cron job). An "automatic" action is triggered when the system reaches a particular state, so you need to compute the state representation and conditionally, when you are in the right state, then automatic action is triggered. This is totally independent of any event (including timers).
Jean-Jacques Dubray
@jdubray
Jan 27 2017 02:17
@ashalkhakov beautiful!
This is not too important, but I would compute state/status in the state function:
model.ticking = (data.tick !== undefined);
Jean-Jacques Dubray
@jdubray
Jan 27 2017 02:25
of course in this case it would be equivalent but sometimes the formula is more complex, like this:
state.counting = function(model) {
    var status = ((model.counter <= COUNTER_MAX) && (model.counter >= 0) && model.started && !model.launched && !model.aborted) ;
    return status ;
}
Jean-Jacques Dubray
@jdubray
Jan 27 2017 02:32
Otherwise, I can't find something else to say. How do you like SAM? (I am looking for an honest opinion, good or bad).
Artyom Shalkhakov
@ashalkhakov
Jan 27 2017 03:35
@jdubray thanks! I'm wondering if state functions are OK to mutate the model? (Which is what you're suggesting.)
Rodrigo Carranza
@DrecDroid
Jan 27 2017 03:36
State is pure, should not cause side effects
Jean-Jacques Dubray
@jdubray
Jan 27 2017 03:37
yes, correct, did I say otherwise?
Artyom Shalkhakov
@ashalkhakov
Jan 27 2017 03:37
I like this approach. Seems to work great for this little game. :smile:
Jean-Jacques Dubray
@jdubray
Jan 27 2017 03:38
yes, it seems everything lands pretty well in place
yet, it's not such a trivial example
Rodrigo Carranza
@DrecDroid
Jan 27 2017 03:40

I was thinking, why instead of passing the propose function like this

function(propose){
   return {
     action1(){
        ...do something
        propose({...}
     }
   }
}

just not returning the proposal and wrapping the action on registration to the system

function(){
   return {
     action1(){
        ...do something
        return {...}
     }
   }
}
Artyom Shalkhakov
@ashalkhakov
Jan 27 2017 03:40
Is there any JSX-inspired source-to-source compiler that compiles straight to string literals? I'd like to write e.g. <xml><div class={myclass} onclick={actions.something}>my data</div></xml> and have it translated into the corresponding string literal, with escaping where necessary and all that.
Jean-Jacques Dubray
@jdubray
Jan 27 2017 04:00
@DrecDroid yes, that works well/better, SAM is entirely agnostic to the wiring used
@ashalkhakov I don't know of any, it's not that much more effort, writing a theme from an HTML5 template is actually pretty pleasant.
Rodrigo Carranza
@DrecDroid
Jan 27 2017 04:05
I've only encountered the problem when dealing with async operations one can't just return the proposal, could return a Promise or use async/await to return a proposal correctly. I asked because I'm trying to find a way of composing actions registered to the system. I register actions like system.registerActions([actions1, actions2)] but If two of them have same named functions the results of the previous should be merged to the results of the next one.
Jean-Jacques Dubray
@jdubray
Jan 27 2017 14:55
@DrecDroid Conceptually, action composition is not possible in SAM since you would break the definition of a step (action->model->state). That being said you can implement a functional/implementation composition, exactly as you are saying, using a pipeline pattern where the code of each function enriches the proposal which is eventually presented to the model.
Rodrigo Carranza
@DrecDroid
Jan 27 2017 15:50
I've tried an seen that is error prone to automatically compose actions that clash with each other, I will left that job to the user to compose their actions using normal functions(without using propose) and then register the action to the system
Jean-Jacques Dubray
@jdubray
Jan 27 2017 15:54
yes exactly, ultimately, the problem in Software Engineering is that we have been writing software using three approximations:
  • Actions can directly impose/control the state of a system (they translate an intent into a proposal)
  • Assignments are equivalent to mutation (a mutation is about "accepting" the proposal)
  • There is no need to have a precise definition of what is a programming "step"
Rodrigo Carranza
@DrecDroid
Jan 27 2017 15:55
I'm working in an image gallery right know and It is extremely useful the pattern in this case because It is easy to mock up the fetching of new images just by creating some actions that fakes data and pass it to the model.
Jean-Jacques Dubray
@jdubray
Jan 27 2017 15:55
SAM removes these three approximations, without much effort on the developer. Someone can learn SAM in 30 min and start using it.
Rodrigo Carranza
@DrecDroid
Jan 27 2017 15:56
It is really simple indeed, to explain and to understand
Jean-Jacques Dubray
@jdubray
Jan 27 2017 15:56
Exactly, and when you connect it to the back-end not much is changing. I do that all the time too.