These are chat archives for jdubray/sam

11th
Mar 2016
Kasper Kuijpers
@stijlfigurant
Mar 11 2016 10:44
im liking this whole SAM thing
going through the http://sam.js.org/ atm
im no computer scientist, but what strikes me as a bit ambigous is that the concept of state is used variably
as in State in SAM being not the concept of state we're used to
maybe its a bit of mental reprogramming required
while at the same time there is mentioned that Model contains all the application state
which is not the same thing as State as in SAM (notice me using State and state to make the difference)
Kasper Kuijpers
@stijlfigurant
Mar 11 2016 10:50
I might be stupid, missing a point or something. But I can imagine this will be a thing especially less experienced people could bump their toe against
weepy
@weepy
Mar 11 2016 10:51
It would be clever to use a different name
Kasper Kuijpers
@stijlfigurant
Mar 11 2016 10:51
Would it be worth renaming State in SAM to something else?
then ofcourse the whole SAM acronym would shatter
but just a thought
because i need to keep track of two mental concepts of state now
weepy
@weepy
Mar 11 2016 10:52
I think it's a good idea.
Could still keep the state
Name mb
Kasper Kuijpers
@stijlfigurant
Mar 11 2016 10:53
and its going to be especially hard in conversation to ensure you are both talking about the same thing that is called state
yep, something like that
again, im still in progress wrapping my head around this thing fully
but this is something that bothered me a bit
weepy
@weepy
Mar 11 2016 10:59
Yes. I think changing the concept name would make it much easier to onboard newcomers
Jean-Jacques Dubray
@jdubray
Mar 11 2016 15:36
At @weepy 's request, the TODOMVC (it hurts) app https://github.com/jdubray/sam-samples/tree/master/todomvc-app
Jean-Jacques Dubray
@jdubray
Mar 11 2016 15:43
@stijlfigurant thank you for your comments. You could also think of it the other way. It's easy to understand that an engine's car is in the "state" started/stopped or the transmission in drive/neutral/reverse/parked.
how do you call these "states"? states?
There is "the state" (property values of the model) and "a (control) state" (started/stopped)
I call the property values the model (they are truly the model of the system) from which you can compute the (control) state
You have to make a computation to decide that the car's engine is in the state "started", there is nothing intrinsic to it
the computation you do is for instance started = (RPM > 0)
If you want to be more correct, you might say started = (RPM > MINIMUM_OPERATING_RANGE) (e.g. 950 RPM).
Then once the car is started, you can shift to "drive" , you cannot take that action, unless the car is started.
would that clear up the language?
Please understand that it is just as confusing to me to call something "state" that does not related to a concept such as "started/stopped".
how do you call the "started/stopped" concept?
Jean-Jacques Dubray
@jdubray
Mar 11 2016 15:50
Going back to the TODOSAM sample, you will see that the View components are pure components (except for the actions, which I will refactor tonight before submitting it to the TODOMVC web site)
weepy
@weepy
Mar 11 2016 15:50
I'm sure there's a word ! You are right that neither is more "correct". His point is just that there's already a status quo on what the word state means in the community.
I was looking at the todomvc. Very nice !
Jean-Jacques Dubray
@jdubray
Mar 11 2016 15:50
Sometimes you have to change the status quo, in French we never ever talk about "Etat" as Model
weepy
@weepy
Mar 11 2016 15:51
Yes you do sometimes. Sometimes it's very hard
Jean-Jacques Dubray
@jdubray
Mar 11 2016 15:51
SAM truly opens the path to create highly reusable View components!!!!!!!!!
weepy
@weepy
Mar 11 2016 15:51
Yes and that's what's important.
Jean-Jacques Dubray
@jdubray
Mar 11 2016 15:51
I also looked at the other implementations and most of them are much larger , for instance the Vanilla-JS implementation
Yes, absolutely, this is where I started (V = f(M)) and that is what changes everything
That relationship is so precious/novel (again, straight from React.js) that you it would be criminal to screw up the business logic underneath.
weepy
@weepy
Mar 11 2016 15:53
m
so if there was a word that could encapsulate "control state" you would consider it ?
Jean-Jacques Dubray
@jdubray
Mar 11 2016 15:53
yes absolutely.
I am French, not native English speaker
weepy
@weepy
Mar 11 2016 15:53
i see
Jean-Jacques Dubray
@jdubray
Mar 11 2016 15:53
when I spoke with Dr. Lamport he suggested to use Control State
weepy
@weepy
Mar 11 2016 15:54
yes i think its quite good
i notice that often you do not even need it
for smaller apps
Jean-Jacques Dubray
@jdubray
Mar 11 2016 15:54
he names his Control States: "pc" in reference to "program counter" (Von Neuman machines)
Yes, please don't get me wrong I am never advocating to use it systematically
It's the 80-20 rule
You won't need it 80% of the time (it-then-else will work just fine)
but when you really need it, it is invaluable
That's the second level of value of SAM, it allows you to partition your business logic in a way that is compatible with state machines (but does not require to implement full state machines)
So you can switch back-and-forth when there is value, and only when there is value
weepy
@weepy
Mar 11 2016 15:56
yes neat
your sample todomvc works really nicely
Jean-Jacques Dubray
@jdubray
Mar 11 2016 15:57
The 3rd level of value is how you connect APIs to the pattern (below Actions and Model)
Yes, I implemented all the functionality, this is the beauty of V = f(M)
It works like a code generator.
It would be much harder to do that with a template mechanism
I believe that the sample also show that the virtual DOM is over-rated
Jean-Jacques Dubray
@jdubray
Mar 11 2016 16:02
In any given (control) state you will always be in the position to replace specific fragments, you don't need a diff algorithm. Again I understand why Facebook needs a diff algorithm, that's over-engineered for most apps
view.display = (representation) => {

    // mount each component in the corresponding div
    Object.keys(representation).forEach(function(el) {
        const component = document.getElementById(el);
        component.innerHTML = representation[el];
    }) ;

    // clean up edited field
    const inputField = document.getElementById('new-todo') ;
    inputField.value = '' ;
} ;
weepy
@weepy
Mar 11 2016 16:34
virtual DOM is for performance
I like your angle for simplicity - but would need to see some benchmarks on real world apps
Stardrive Engineering
@HighOnDrive
Mar 11 2016 17:06

@jdubray "so if there was a word that could encapsulate "control state" you would consider it ?"

I've been using the word ''modus" as in modus operandi. It then represents the special dynamic control state that the app is in (a la the RxJS projected state via the scan operator) or a unique active control state (as in FSM state) the app has been transitioned to.

Here is an interesting article, one for the list: http://www.catonmat.net/blog/frameworks-dont-make-sense/
Jean-Jacques Dubray
@jdubray
Mar 11 2016 17:13
@weepy , I am not saying never use virtual-DOM, but I can bet you that I can beat diff algorithms in over 95% of the cases with a component based view and a simple render true/false strategy.

so if there was a word that could encapsulate "control state" you would consider it ?

I would if it starts with S or a letter that makes the TLA attractive

Actually in the getting started guide, I suggest that we can view SAM as "PAL" (Propose, Accept, Learn).
The only reason I am attached to SA if for the reference to State-Action. I spent literally my entire career to bring "State" in the programming model. This is the best shot I ever had.
Stardrive Engineering
@HighOnDrive
Mar 11 2016 17:18
Yes, it is tough satisfying a acronym :smile:
Jean-Jacques Dubray
@jdubray
Mar 11 2016 17:20
PAL semantics are isomorphic to SAM, so I am happy to "S"witch. :-)
Stardrive Engineering
@HighOnDrive
Mar 11 2016 17:22
Its a bit like taking a dump through a straw, lol. I'm not yet convinced the whole world of reactive programming can be reduced to SAM. The tide has risen and the waters are deep in places, there is much to consider and really the only way to do that is build an app that stretches the mind to new dimensions.
weepy
@weepy
Mar 11 2016 17:22
It seems slightly strange that State is apparently so important that it's in the title. And yet it's not even used much of the time ?
Jean-Jacques Dubray
@jdubray
Mar 11 2016 17:23
well, yes and know, because it computer science was truly based on State-Action our lives would be horrible
my rule of thumb is that you need state less than 1% of the time (say on average) but when you need it, and you don't use it, you are dead.
weepy
@weepy
Mar 11 2016 17:24
You said "you won't need it 80% of the time" ... Does is deserve its place it the acronym ?! :-)
Jean-Jacques Dubray
@jdubray
Mar 11 2016 17:24
Let me qualify: Front-End architecture -> 80%-20%
Computing -> 99%-1%
you don't need "state" in algorithms for instance or extremely rarely
much less than 1% of the time.
If you look back at the code you wrote, how often would you have needed "state"?
20% or 1%?
the problem is that you cannot, absolutely cannot ignore these 1% (or 20%)
Front-End architecture are essentially state machines: State/Actions/State/Actions/State/Actions
Stardrive Engineering
@HighOnDrive
Mar 11 2016 17:28
Staltz and everyone in the Rx community would so disagree with you, this is their creed:
this is cycle.jpg
So, in the reality of real world modern apps there are two essential types of control state, the one Staltz preaches and the one that FSM's promote, which to me is a pre-defined group of properties that can declare just about anything if you wish.
Jean-Jacques Dubray
@jdubray
Mar 11 2016 17:39
It's hard to comment for me real-time but the notion that you can take an arbitrary action on a system at any time is simply ludicrous.
to start with his model is missing nap()
the view is secondary to the pattern, the core is SAM (State Action Model), there can be many views, we live in a multi channel views
MVC was invented to introduce the perspective of the user into the design, but we have to consider the user, the user's friend, his smartwatch and uber driver ready to pick him up.
The "V" world is flawed from the get go.
We should be talking about the "Vs"
and hence the View is irrelevant, only SAM is
Mutating the "state" (what I call model) in an atomic operation is a consequence of an architecture choice (virtual dom), not a pattern
For many reason, I do not trust what Dan and André are talking about. A pattern must work for all or as many architecture as possible.
Jean-Jacques Dubray
@jdubray
Mar 11 2016 17:45
They are great software engineer, I am not, but I am a ruthless modeler. Semantics are at the core of what we are discussing, not "wiring" or "code".
or even "architecture"
Stardrive Engineering
@HighOnDrive
Mar 11 2016 17:48
It all sounds a bit lacking to me, nothing beats real world requirements in the end. Myself, I am glad both types of control state (which I defined above) exist. There are certainly many types of control state that can be dynamically processed or projected. Saves in managing a whole ton of what should be transient properties.
Jean-Jacques Dubray
@jdubray
Mar 11 2016 17:50

There are certainly many types of control state that can be dynamically processed or projected

yes, that's the idea behind S( ), this is where you handle that concern. This is nowhere near where Redux or Cycle are. For them, the store gets updated atomically, then they trigger the virtual dom.

the conflate View and the State function. Really bad coupling
They can change their "views" easily, but so far neither Dan or André seem to agree
or even understand the question
S() is a function, so it is always dynamically processed and projected
it is for all intent and purposes stateless
Stardrive Engineering
@HighOnDrive
Mar 11 2016 17:54
Well, Cycle.js adheres to it's MVI pattern so there is a specific place for each concern, yet MVI is not demanding, you can still slice and dice it as you require.
Jean-Jacques Dubray
@jdubray
Mar 11 2016 17:57
A pattern actually has to be prescriptive/demanding about its semantics, that's the point . You can still "wire" it or "Architect" it as you require.
Stardrive Engineering
@HighOnDrive
Mar 11 2016 17:58
Basically, Dan came up with his creation before the knowledge of Rx reached his ears and André, will he is generous in his constraints yet advocates a higher order pattern, namely side-effect free FRP.
Jean-Jacques Dubray
@jdubray
Mar 11 2016 17:59
I believe there is a real opportunity to layout everything pattern, wiring and architecture and nobody wants to talk
Jean-Jacques Dubray
@jdubray
Mar 11 2016 18:06
@brucou is funny, "A model M which is hashmap with a set of properties"
Stardrive Engineering
@HighOnDrive
Mar 11 2016 18:08
Yeah, going to have a look...
Stardrive Engineering
@HighOnDrive
Mar 11 2016 18:33
Here are also some good reports about how far we have come since the MVC of the 80s, the slides are worth noting :
Jean-Jacques Dubray
@jdubray
Mar 11 2016 18:39
Who is @brucou again?
Alex
@whitecolor
Mar 11 2016 20:02
How does SAM refers to Event sourcing?
Jean-Jacques Dubray
@jdubray
Mar 11 2016 21:35
@whitecolor Alex, I believe SAM offers a better foundation for Event Sourcing because of the decoupling between the Proposal (Action) and Acceptance (Model) of the property values. When you are not using Thunks in Redux then you have anemic intents instead of actions.
Event Sourcing is generally better applied at the "Acceptance" level not the "Proposal" level. This is how Gunar's Time Travel implementation for SAM works. However, you could also apply in some cases at the Proposal level as long as you understand the implications/or your actions are pure functions.
Alex
@whitecolor
Mar 11 2016 22:04
@jdubray Thanks, does anyting particular you see really hinder to implement SAM approach using cycle.js as foundation? I believe cycle is actually quite agnostic to arichitecturing state/models/actions/or any other things.
Jean-Jacques Dubray
@jdubray
Mar 11 2016 22:09
@foxdonu has created a sample and @HighOnDrive think it's a great architecture to implement SAM
The only reservation I have is that the model subscribes to all the actions, there fore the model has to decide to either accept any action (which I believe is bad) or make the decision as to in the current state whether an action is authorized or not. I would prefer doing that outside the model
State and Actions can be lightly coupled since there is a duality to them, but I would prefer building a container in State-Actions container in cycle.js or that then presents a valid action's intent to the model. I don't think that's really hard to do.
Jean-Jacques Dubray
@jdubray
Mar 11 2016 22:24
personally, I just don't see the "everything is a stream" approach. I have expressed several time before that we should be extremely careful in architecting/factoring a system around a monadic approach (everything is a XXX where XXX = Class, Function, Process, Actor, Stream) as they seem to generate more problems than they solve.
If the problem you are trying to solve is the boiler plate code that connect's a display's event to your actions, SAM solves that problem very simply via "code generation". V = f(M) is a mini code generator that makes sure that your view is always wired to the right action effortlessly.
Alex
@whitecolor
Mar 11 2016 23:09
There is None Else Beside Him
Jean-Jacques Dubray
@jdubray
Mar 11 2016 23:13
well ultimately SAM has to solve enough of the problems that people encounter in Front-End architectures. There is probably a good reason why you see streams as a particular solution.
Alex
@whitecolor
Mar 11 2016 23:13
I think there is better to be more concrete what problems does particular approach create like "everything is a stream", otherwise "generate more problems than they solve" are just words
people actually "generate more problems than they solve")
in general ;)
Jean-Jacques Dubray
@jdubray
Mar 11 2016 23:14
It depends on your perspective.
V = f(M) is certainly one of most powerful thing I have seen in software engineering in a long time (courtesy of React.js)
Alex
@whitecolor
Mar 11 2016 23:16
in event soursing concept event streams are conner stone thing
Jean-Jacques Dubray
@jdubray
Mar 11 2016 23:16
yes, I don't dispute that...
that being said, a UI seems to be a really poor stream of event ...
Except for a few types of events that are rarely used, a GUI emits one event before it dies. You would consider (if not agree) that Streams could be a bit overkill to manage one event
Alex
@whitecolor
Mar 11 2016 23:18
what you mean by only one event?
Jean-Jacques Dubray
@jdubray
Mar 11 2016 23:19
submit form. How many UI track the mouse or the keyboard?
When you initiate an action (and start the reactive loop), the view does not wait for a response, there is no response in a reactive loop
Alex
@whitecolor
Mar 11 2016 23:20
hm we are talkin about SPA mostliy
Jean-Jacques Dubray
@jdubray
Mar 11 2016 23:20
the views dies and is replaced by a new view (logically)
yes, that's what I am talking about too
I believe you are not realizing that the semantics is that at the end of the reactive loop it is always a new view that is displayed in lieu of the old one
Alex
@whitecolor
Mar 11 2016 23:21
take some messaging interfaces/chats/etc
Jean-Jacques Dubray
@jdubray
Mar 11 2016 23:21
it is not req/resp
no, sorry, that is not reactive
that is actually the problem
Alex
@whitecolor
Mar 11 2016 23:22
what you mean not reactive?
Jean-Jacques Dubray
@jdubray
Mar 11 2016 23:22
the "state representation" is a new rendering of the model (property values)
interactive: req/resp
reactive: message passing V -> A -> M -> S -> V+1
this is from André's own words
It is agreed that for optimization purposes and the use of the virtual-dom the view container reuses V to make the display of V+1 more efficient, but it is truly V+1 that you are displaying you are not changing V
Alex
@whitecolor
Mar 11 2016 23:23
its cycle of the streams
its more than enough for streams to used there
Jean-Jacques Dubray
@jdubray
Mar 11 2016 23:24
well, I would ask the question to André, but interactive is request/response if you have a request/response somewhere you are not reactive
sure, my perception is that it's a bit overkill.
It does not mean that I dislike it, but I don't see the point.
Alex
@whitecolor
Mar 11 2016 23:25
I think you just should probably try it more in business)
it works really great
and I'm sure its a perfect foundation for implementing your SAM approach
Jean-Jacques Dubray
@jdubray
Mar 11 2016 23:26
well again, I see it as pure wiring, being a server-side guy, I don't run much code on the browser/client
Alex
@whitecolor
Mar 11 2016 23:27
you may run cycle on server)
Jean-Jacques Dubray
@jdubray
Mar 11 2016 23:27
perfect is perhaps an overstatement, but again, there are semantics/wiring/architecture
Alex
@whitecolor
Mar 11 2016 23:27
I do
Jean-Jacques Dubray
@jdubray
Mar 11 2016 23:27
I only talk about semantics, I don't want to tell people how they should wire SAM or architect their application
that would defeat the purpose of being a pattern
I'd be more than happy to see SAM adopted by the Cycle.js community
Alex
@whitecolor
Mar 11 2016 23:28
but solid examples of implementataion should be there
Jean-Jacques Dubray
@jdubray
Mar 11 2016 23:28
Well I wish I had more time/skills to do that, but I don't get paid to work on SAM, just yet.
I did my first training this week
Alex
@whitecolor
Mar 11 2016 23:30
maybe some video with explanation will be good to have for the beginning