These are chat archives for jdubray/sam

14th
Mar 2016
Jean-Jacques Dubray
@jdubray
Mar 14 2016 00:25
@mbsimonovic the two are connected at the hip (or heap?). You can't "react" to just about any garbage event.
@HighOnDrive no matter how much I like state machine, I still believe you can't code with them. In the first part of my career I worked on some advanced semiconductor deposition systems which require complex control loops, they make a lot of sense there (since you could damage the equipment or fail the recipe). In the context of business processes, they also make a lot of sense in terms of "Business Entity Lifecycles".
Heck, I even created an abstract definition of problem statements from state machines.
Jean-Jacques Dubray
@jdubray
Mar 14 2016 00:30
and with that, I rewrote the way you specify requirements/user stories, which are always written from a "solution" perspective when you use an action (as opposed to a state = problem).
But, with all that being said, I would never write code as a state machine, so even SAFE has as little as possible of FSM semantics, just enough. I'll never create a DSL for FSM, been there, done that. I am an if-then-else guy.
Stardrive Engineering
@HighOnDrive
Mar 14 2016 04:43
Just read the following article that was linked to this room earlier. It describes a type of FSM that is suited for the event-driven paradigm. The end solution in the article starts approaching the kind of FSM I'm talking about. This is one of the best articles I've read in a while and it was from 2003, at the tail end of the dot.com era!
I'm not a "if-then-else guy" if I can help it. Would much rather have the right FSM abstraction and awesome Rx operators to power my reactive loop :fire:
Stardrive Engineering
@HighOnDrive
Mar 14 2016 05:16
Just read the following article and when reading about offering "profiles" it struck me that the way i define my FSM already handles that too. Having "One API (the right FSM abstraction), Many Facades" works well for me.
Jean-Jacques Dubray
@jdubray
Mar 14 2016 10:28
@weepy really?
class Counter extends Component {
  constructor(props) {
    super(props);
    this.state = { counter: 0 };
    this.interval = setInterval(() => this.tick(), 1000);
  }
If Dan is interested in "hot reloading", again he cannot ignore the semantics of State Machines. You can't arbitrarily Hot Reload any thing you want. A "class" is the last thing on earth you want to hot reload...
Jean-Jacques Dubray
@jdubray
Mar 14 2016 10:38

@HighOnDrive @mbsimonovic @brucou Let me try to change your perspective.
Imagine you never heard of state machines before, and someone tells you:

Imagine a world in which physicists did not have a single concept of
equations or a standard notation for writing them.
... Teaching our imaginary physicists that einsteinians and heisenbergians
are different ways of writing equations would not lead to any new physics.

Then that someone explains to you:

State machines provide a framework for much of computer science. They
can be described and manipulated with ordinary, everyday mathematics—
that is, with sets, functions, and simple logic. State machines therefore
provide a uniform way to describe computation with simple mathematics.

Now, it does not mean that the way you think about state machines is wrong at all, State Machine formalisms come a dime a dozen. Now can I use TLA+ to describe all of them? you bet.
Jean-Jacques Dubray
@jdubray
Mar 14 2016 10:45
I understand, that it's a bit hard to swallow, as it was hard for me, it's like where are the (control) "states" in TLA+, I can't see them, therefore TLA+ is not a state machine formalism, it is something else.
That's until you realize that you can map all state machine formalisms to TLA+. I dream I could be this great mathematicians and write a couple of equations that demonstrates this, but I am not, by any means. So let me show you the only thing I can do as a matter of "proof" (and I understand that @brucou would have reservations about this kind of "proof"), let me show you an example, the Die Hard problem: http://www.ebpml.org/blog15/2015/01/tla-the-die-hard-problem/
I found this problem interesting because it shows how a "state machine" computes (as opposed to how a program implements the semantics of what we traditionally call a state machine)
Jean-Jacques Dubray
@jdubray
Mar 14 2016 10:50

TLA+ IS_THE underlying formalism of all state machines because it is absolutely and definitely prescriptive about answering these questions

To describe a program as a state machine, we must decide what constitutes
a step. How many steps are performed in executing the statement
f = i ∗ f of the programs in Figure 1? Does a single step change the value
of f to the product of the current values of i and f ? Are the evaluation of
i ∗ f and the assignment to f two steps? Are there three steps—the reading
of i, the reading of f , and the assignment to f ?

You can't make up these answers, you can't just pick and choose as "einsteinians and heisenbergians"
The true genius of Dr. Lamport has been to see beyond the semantics of FSM. As a physicist that's very disappointing, because personally like you guys, I can "see" the (control) states and TLA+ does not look like a formalism of what I was lead to believe IS_A state machine
Therefore, I'd like to reiterate that TLA+ IS_THE foundation of computing, everything you do, absolutely everything you do must be aligned with it, otherwise proceed at your own risk.
That's why, when I see kids like Dan come up with code like this:
class Counter extends Component {
  constructor(props) {
    super(props);
    this.state = { counter: 0 };
    this.interval = setInterval(() => this.tick(), 1000);
  }
I just want to cry
Jean-Jacques Dubray
@jdubray
Mar 14 2016 10:55
That's why when I see @brucou throw at my face the "extended state machine" semantics and tell me I have no clue as to what I am talking about, I just want to cry.
Because, what you guys are looking for is right there, before your eyes, it is so simple that you might believe it not true. Yet it is it, TLA+.
State machines can be described and manipulated with ordinary, everyday mathematics—
that is, with sets, functions, and simple logic.
State machines therefore provide a uniform way to describe computation with simple mathematics.
Milan Simonovic
@mbsimonovic
Mar 14 2016 11:01
a side not on "hot reloading": this should be done at the language level (like in elm), not at the framework/pattern/solution level. i don't want to be constrained while coding a solution because one way allows for hot reloading and another doesn't
Jean-Jacques Dubray
@jdubray
Mar 14 2016 11:08
well, there are constraints. unfortunately.
weepy
@weepy
Mar 14 2016 11:23
Well if we are stuck with JavaScript then we can't really !
Jean-Jacques Dubray
@jdubray
Mar 14 2016 11:38
Well, again define "hot reloading", if it is all about putting a system into a given "state" after you have changed the code, then it is not a question of language but semantics. There is nothing "hot" about reloading...
Gunar C. Gessner
@gunar
Mar 14 2016 12:21
Both samjs and samjs-devtools now have "Help wanted" issues, if anyone would like to jump in, this is a great opportunity to contribute to OSS :) https://github.com/sam-js/sam/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22 https://github.com/sam-js/sam-devtools/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22
Milan Simonovic
@mbsimonovic
Mar 14 2016 12:48
i don't see (yet) that TLA+ is THE foundation of computing, for now it is 'just a formalism', built on top of temporal logic, which is a type of modal logic with modalities of time, so it can be used to reason about temporal properties
i have to say @brucou's remarks are sound, on a first look SAM does look like EFSM
Milan Simonovic
@mbsimonovic
Mar 14 2016 13:00
all these discussions are leading me to believe Dr Lamport was right yet again when he said "clear up your thoughts and submit a paper", we should be more rigorous when talking about these things, properly (possibly formally) define what is meant
for example, it would be awesome to have SAM defined in TLA+
José Pedro Dias
@JosePedroDias
Mar 14 2016 13:48
@jdubray I added my interpretation of SAM to the example impl
https://github.com/JosePedroDias/sam_rocket_w_snabbdom
Brian Haak
@avesus
Mar 14 2016 14:02
Milan Simonovic
@mbsimonovic
Mar 14 2016 14:16
one more thing regarding 'the formalism': wasn't it the church thesis that said you cannot define a formalism without choosing which kind of computation you want to express with it? so depending on the 'kind of computation' you'll end up with different formalisms (some might be compatible). therefore there cannot be one true formalism for the entire computing. i might be wrong here, don't remember how exactly was it stated
Stardrive Engineering
@HighOnDrive
Mar 14 2016 14:24
@jdubray "There is nothing "hot" about reloading...". Well, the hot part is in the name because of how and when the reloading is done, which is while your editing. That is actually incredibly hot compared to the old compile then run steps that needed to be done over and over wasting a ton of time. It is not a question of language but semantics but of efficiency.
@mbsimonovic I would tend to agree with the the church thesis. This is also why a simple pattern might do in some apps while a more complex state machine is required in others. One size fits all is hard to do.
Jean-Jacques Dubray
@jdubray
Mar 14 2016 14:42
@mbsimonovic @HighOnDrive It looks like I am not going to be able to convince you, you are referring to research that pre-dates TLA+ as if there was nothing else to add. I am not of the caliber to write research paper in Computer Science, so you'll have to excuse me from that discussion. All I can say is I have tried to align SAM as best as I could with the semantics of TLA+ and as a results SAM aligns readily with any SM semantics, yeah, including the extended SM ones (surprising isn't it?) and Praxos as well. If I had make some mistakes in the interpretation of TLA+ I believe that there would be some programming semantics that cannot be landed easily on top of SAM... (just saying).
Jean-Jacques Dubray
@jdubray
Mar 14 2016 14:49
@JosePedroDias That's a great illustration, I would prefer the State function to use the state predicates to decide which components to activate, rather than the view knowing about them.
In the TODOSAM sample I tried to isolate the view components completely from the underlying business logic with the concept of "intents" that are passed to the view to wire itself to the underlying actions: https://github.com/jdubray/sam-samples/blob/master/todomvc-app/js/app.js
theme.list = (todos, displayActive, displayCompleted, intents) => {
The goal is truly to enable people to create library of reusable components. It SAM could achieve that, that would be a major step forward (I believe it can).
On that note, I would rather call "intents" a signal to invoke an action rather than the invocation of the present method, but that's just a label/wiring, intents are not part of the semantic foundation of TLA+
Stardrive Engineering
@HighOnDrive
Mar 14 2016 15:00
@jdubray "intents are not part of the semantic foundation of TLA+". Of course not, they hardly knew what a mouse was back then!
"I would prefer the State function to use the state predicates to decide which components to activate, rather than the view knowing about them", right √
José Pedro Dias
@JosePedroDias
Mar 14 2016 15:06
thanks for the feedback.
What I find truly misleading when reading the docs is STATE
it is kind of a bag of aux function capable of identifying the app state and a view electing algorithm
when one reads STATE usually it means app state, which it is NOT
I'll take a look at your todo impl when I get the time (in my day job now)
there's one exercise I wasn't able to do in SAM
can an app be segmented into smaller apps/components?
of course the view functions can (receiving subsets of the model)
but the whole app I'm not sure
Jean-Jacques Dubray
@jdubray
Mar 14 2016 15:16
Yes, actions are naturally segmented, and again I would expect there would be libraries of functions perhaps, just with a simple adapter to the model model.present(adapter(A(data))). Imagine a validate address function where the address format is translated by the adapter into something can work with.
The model implementation itself needs to be broken down, but generally along CRUD lines (not always possible) rather than Action lines.
You can check the model in the TODOSAM sample:
model.present = (data) => {

    data = data || {} ;

    model.presentFilters(data) ;

    model.CRUD(data) ;    

    model.postProcessing() ;

    // next step of the reactive loop: compute the state representation   
    state.render(model) ;
}
The State can be broken down by "control state", "pages", ... any logical organization of your app that you compute with either state predicates (if it is easier) or simple if-then-else.
when one reads STATE usually it means app state, which it is NOT
I have discussed that point at length, it is just as misleading to think the app state is just a set of property values (at least for me).
Jean-Jacques Dubray
@jdubray
Mar 14 2016 15:22
The State translates the property values into the "current/control" state of the system. The property values (aka the app state) tell you nothing about that "state".
I can even build systems with the same model but a different "state" function
Again, this is an essential aspect of the factoring, it's not something that's arbitrary. If it helps, you can call "state" the true app state (which is is).
Would that work for you?
José Pedro Dias
@JosePedroDias
Mar 14 2016 15:55
what would you call what is now named as state, in such case?
Jean-Jacques Dubray
@jdubray
Mar 14 2016 16:59
As I mentioned before state and model are different in nature:
http://www.ebpml.org/blog2/media/blogs/CarnetsdeBord/star.png
"State" Machines use the word "state" properly IMHO. We unfortunately started to use "state" incorrectly because there was a good noun representing "a set of property values"
I am not very good at picking up names... but so far I'd rather use "model" because it can be used both as a "structure" (type) and "instance of a structure" (this is the "model" of that particular system, e.g. that car with that amount of gas, battery, coolant) and also because of MVC. No one seems be talking about the State View Controller pattern.
Michael Terry
@formido
Mar 14 2016 17:08
Model and View and Controller are categories of code, whereas we think of state as a run-time issue, so State View Controller wouldn't make sense
it's useful to continue to hash out the naming to see whether new terminology would be better or to decide whether it's the best advantage to fight through the confusion
Jean-Jacques Dubray
@jdubray
Mar 14 2016 17:18
Well, State is clearly a category of code (the State function is very distinct to what you would put in the Model), we are just running out of nouns. Again, happy to adopt a new terminology, but agree, it would have to make sense.
José Pedro Dias
@JosePedroDias
Mar 14 2016 17:36
I see
created a browserify branch and a crude SAM glue function
not that happy with the result though. does add much (comparing to setting it up by hand)
functions have to receive several args, when set up from outside
Jean-Jacques Dubray
@jdubray
Mar 14 2016 17:42

Jose, did you see SAFE? https://github.com/jdubray/sam-safe/blob/master/safe.js it does some wiring for you.

// Business Logic - SAM Pattern
var actions = null ; // not implemented on the server
var model = require('./model') ;
var view = require('./view') ;
var state = require('./state') ;

var safe = require('./safe') ;

safe.init(actions,model,state,view) ;

If you did, anything you didn't like about it?

José Pedro Dias
@JosePedroDias
Mar 14 2016 18:22
I haven't yet seen safe, no
Jean-Jacques Dubray
@jdubray
Mar 14 2016 18:26
SAFE is a micro-middleware for the State-Action part of SAM, of course it connects to the Model and the View. From a dev tools perspective, SAFE also aims at providing a server-side version of Time Travel with code reloading capability (restart your node process).
José Pedro Dias
@JosePedroDias
Mar 14 2016 18:30
hmmm ok. will take a look. thank you
Milan Simonovic
@mbsimonovic
Mar 14 2016 19:14
@jdubray i don't need a paper to be convinced, can do that by getting some experience with the pattern, but having a well defined document would go a long way
i'm still browsing around the literature, just run into this thing: http://cacm.acm.org/magazines/2012/7/151241-behavioral-programming/fulltext
seen that before maybe?