These are chat archives for jdubray/sam

28th
Feb 2016
Troy
@troyji
Feb 28 2016 02:47
blob
Troy
@troyji
Feb 28 2016 04:01
I have refined my SAM / View Model (knockout.js data binding) Sample to reflect the diagram above: https://jsfiddle.net/80xzt848/1/
I have added an input field for updating the starting value of the counter. This demonstrates 2-way data binding in action and how the data flows in/out of SAM.
Michael Solovyov
@msolovyov
Feb 28 2016 04:09
I did a similar example with vue.js but what I've come to is the two way binding is more trouble than it's worth. It makes it way too tempting to short circuit the sam loop
Data should really be made to flow one way through the pattern, otherwise bugs and risks cam arise if it's two way
Can *
Troy
@troyji
Feb 28 2016 04:12
It is tempting to merge the View Model with the Action layer. In some cases, it might make sense to pass the actions into the view model during the display phase. However, in this case the data binding library (knockout.js) passes its own variables into the bound functions. So the view model must wrap the standardized actions. This is only really necessary if you want the actions to support multiple views / devices.
Michael Solovyov
@msolovyov
Feb 28 2016 04:15
I've also come around to building the view through a function instead of the html binding way
Jsx really makes it elegant
Troy
@troyji
Feb 28 2016 04:15
@msolovyov, in this sample, the data does flow one way (as you see in the diagram). The data-binding is only there to help you push/pull data into the DOM. This way you don't have to wire up to DOM events and search out DOM nodes to manage the view data - the data-binding system does magic for you. Beyond this, the model should call into actions in SAM. Once SAM is finished, a new view model is generated (because the model is the master data source).
Michael Solovyov
@msolovyov
Feb 28 2016 04:17
I'm not saying it's not sam. My vue example is sam as well. It's just awkward and risk prone. While I do agree it's nice to have that view magic
Troy
@troyji
Feb 28 2016 04:30
@msolovyov, the background to this is that I am a strong believer in declarative binding over imperative binding. For folks like me, we demand that we tell UI elements what data to read/write against instead of writing code to search out UI elements where we want to push/pull our data. Depending on your data-binding library, it may not be possible to bind against POJOs (i.e. the Model). In the case of knockout.js, you must bind against non-POJO observables. Thus we must introduce the View Model where bindable observables live.
Furthermore, if the library does support binding against POJOs, it would break the SAM model to allow data to be pushed directly into the Model. So in that case, we would still require a View Model to stage the view's data.
Troy
@troyji
Feb 28 2016 04:42
@msolovyov, would you mind elaborating on the 'awkward and risk prone' challenges that you encountered? Do you think it comes down to preference of where you handle view wiring/transformations, or do you think the View Model approach diminishes the value of implementing SAM?
Troy
@troyji
Feb 28 2016 05:06
@jdubray, please update the link for my knockout sample to this refined version: https://jsfiddle.net/80xzt848/1/
Michael Solovyov
@msolovyov
Feb 28 2016 06:39
@troyji I only noticed it when I did the list todo example with vue.js when you have input fields that are automatically two way binding, you end up having to separate your model out into two parts, one for the two way binding and the other for storage from the present function
Because otherwise the flow is view to directly model. It's just very easy to do because those frameworks are geared for that flow
So you end up fighting them a bit to get it to be sam
Michael Solovyov
@msolovyov
Feb 28 2016 06:49
The risk comes in when you have other devs coming in, because they're likely to use the framework as intended and not sam. Or mixing.
Jean-Jacques Dubray
@jdubray
Feb 28 2016 15:28
apologies, I was traveling, will update the link shortly
@msolovyov can I add your vue.js example to the list of code samples?
Michael Solovyov
@msolovyov
Feb 28 2016 15:29
Sure
Jean-Jacques Dubray
@jdubray
Feb 28 2016 15:29
thank you
Jean-Jacques Dubray
@jdubray
Feb 28 2016 15:46
Ok, added both samples
Milan Simonovic
@mbsimonovic
Feb 28 2016 15:50
Jean-Jacques Dubray
@jdubray
Feb 28 2016 15:50
@troyji @msolovyov wrt to the discussion on view-model I added a headless version of the pattern.
Milan Simonovic
@mbsimonovic
Feb 28 2016 15:51
just started reading the paper but sounds like a good formalism for a web framework
there're probably frameworks for generating FSMs based on some dsl description
Jean-Jacques Dubray
@jdubray
Feb 28 2016 15:53
I am certain there will be a number of libraries / frameworks that facilitate the wiring.
the next level is facilitating the construction/decomposition of the S() function
V = S( page1(M) + page2(M) + page3(M))
page1(M) = furniture(component1(M)+component2(M)+...)
when it comes to the State Machine formalism, I already wrote a library compatible with SAM
@mbsimonovic State Machines are really a pain to program with, so they should be used when they are absolutely necessary
It really set the stage for TLA+ and hence SAM
Milan Simonovic
@mbsimonovic
Feb 28 2016 15:57
that's lamports paper right
yes i know about scm, been thru all your blog posts related to scm
sam
Jean-Jacques Dubray
@jdubray
Feb 28 2016 15:58
Section 3 of this paper kind of explain the relationship between state machine and programming

the key question is as he states:

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 ?

SAM decomposes the business logic in a certain way. Redux has chosen a different way
As he explains, it's not like there is an absolute best way to do it, but in the present case, I believe that Action-Model-State is superior to Action-Reducer-Store-Saga
I know it's a bit like splitting hair, but I truly believe that this question is essential to the Front-End architecture, in particular giving you the ability to distribute components (including APIs)
Milan Simonovic
@mbsimonovic
Feb 28 2016 16:02
yes, that's the core issue, how to implement the business logic
Jean-Jacques Dubray
@jdubray
Feb 28 2016 16:02
Yes, there are a lot of frameworks/DSL for FSM
But please note that in SAM the State Machine is further decomposed, please see the discussion here:
Milan Simonovic
@mbsimonovic
Feb 28 2016 16:02
take the counter example, there's a single FSM that describes it, but it can be implemented in a number of ways
right
SAM is one
backbone another, react/redux, ..
Jean-Jacques Dubray
@jdubray
Feb 28 2016 16:03
Yes, absolutely, that's the point of Lamport
But he advises that we should never lose sight of the State Machine
The State Machine is the structure of what happens
Milan Simonovic
@mbsimonovic
Feb 28 2016 16:04
so my question was there have probably been a number of attempts and evaluations of how to implement FSMs, and could we learn from that or possibly reuse some of those implementations
Jean-Jacques Dubray
@jdubray
Feb 28 2016 16:04
even though the semantics of frameworks and programming languages may make writing some state machines more elegant
Milan Simonovic
@mbsimonovic
Feb 28 2016 16:04
or even generate an implementation
given some DSL description of a FSM
Jean-Jacques Dubray
@jdubray
Feb 28 2016 16:04
I would discourage doing that.
Milan Simonovic
@mbsimonovic
Feb 28 2016 16:05
and plugin some pieces of logic here and there (what happens in a given state, etc)
Jean-Jacques Dubray
@jdubray
Feb 28 2016 16:05
If you read Lamport's paper, the State Machine is about integrity / structure
but, it is not about "execution"
My impression is that state machines are highly inefficient to code
This has been true for decades.
Milan Simonovic
@mbsimonovic
Feb 28 2016 16:07
i don't see why using a generated implementation would violate integrity, on the countrary
Jean-Jacques Dubray
@jdubray
Feb 28 2016 16:07
SAM brings some balance between the ability to use the structure of state machine (state-action) without the burden of full SM semantics
it's not about integrity
Milan Simonovic
@mbsimonovic
Feb 28 2016 16:07
but it was just a thought, need to spend more time investigaing
will come back soon
Jean-Jacques Dubray
@jdubray
Feb 28 2016 16:07
it is about efficiency of the code, I believe JavaScript is enough
Milan Simonovic
@mbsimonovic
Feb 28 2016 16:07
yes, that's what i was asking about
Jean-Jacques Dubray
@jdubray
Feb 28 2016 16:07
Even if you look at SCM, it can become quite heavy
Sorry have to board a flight
Jean-Jacques Dubray
@jdubray
Feb 28 2016 19:51
@mbsimonovic I would actually encourage anyone to focus on TLA+ rather than State Machines. If you are looking at that tutorial (section 3). TLA+ is quite rich and there is a lot more to it than what I grabbed for SAM http://www.loria.fr/~merz/talks/argentina2005/slides.pdf
I have been building DSLs for the past 25 years and the problem with DSL is that you can rarely define meaningful computations. I wrote a paper a few years ago talking about "metaprogramming": http://www.infoq.com/articles/mop
Jean-Jacques Dubray
@jdubray
Feb 28 2016 20:00
In essence the difference between MDE and metaprogramming is that the code of the solution is always 100% generated, in other words the developer is allowed to modify the DSL to achieve a 100% generated solution
That's perhaps why I like the V = f(M) so much when compared to template.
Milan Simonovic
@mbsimonovic
Feb 28 2016 20:51
yes, i'm familiar with that, while at college our professors were pretty sure CASE tools and metaprogramming will soon take over and no one will ever have to write code :)
but i wasn't keen on that, just thought implementing FSM must be a very well explored topic and that web frameworks could be nicely formalised as FSMs, so all that knowledge and experience could be exploited
Jean-Jacques Dubray
@jdubray
Feb 28 2016 20:56
actually metaprogramming is completely different from traditional MDSD/MDE it is just a different way of writing code. It's not a tool
Milan Simonovic
@mbsimonovic
Feb 28 2016 20:56
will have a look at tla first
Jean-Jacques Dubray
@jdubray
Feb 28 2016 20:57
metaprogramming is based on the fact that we write code in 3 dimensions:
  • programming model
  • solution model
  • technical model
programming model is like OO, FP, SM, ...
solution model is logically what you are building
technical model is everything else (libraries, frameworks, ...) that allow you build the solution
Every developer write code that way (more or less consciously)
metaprogramming allows the developer to change the programming model to align it more closely to the solution.
SAM is at the programming model level
and V = f(M) is part of translating the solution into an executable.
Milan Simonovic
@mbsimonovic
Feb 28 2016 21:04
i have a more pragmatic definition of metaprogramming in mind, like what's commonly used in the dev circles - to mess with the language's core constructs, or define new ones
so let's say emulate classical OO in javascript just by using functions
Jean-Jacques Dubray
@jdubray
Feb 28 2016 21:06
yes, I understand, there has been quite a bit of interest in metaprogramming in the past few years
but in the end, it is really about giving the ability to the developer to influence the programming model
Milan Simonovic
@mbsimonovic
Feb 28 2016 21:07
to answer your earlier comment, it was exactly what i was thinking the whole time while reading your blog posts: having some framework around SAM would instantly make it much more marketable
devs would be able to pick it up and code some cool examples to impress their peers, spread the word ...
now they have to read, a lot :) before they can get their hands dirty
do you know how SAM behaves when you push it to a biggish code base? in other words, how does it scale?
Jean-Jacques Dubray
@jdubray
Feb 28 2016 21:17
I am building an ecommerce website with it right now and so far, it has shown no problem.
I only have 24 h a day, so it's not practical to build a framework beyond SCM/STAR
That being said, even with a framework what is hard to grasp is V = f(M), this is true of React too
What's worse in React is that you do not have a nice hand off between the business logic and the components.
The SAM parts of the pattern, I believe anyone can get, this is just basic FP
Milan Simonovic
@mbsimonovic
Feb 28 2016 21:21
i'm not saying you should do it :)
but just think a great framework would help put developers on the right track
yes, but have a look at the HN tread, how many of them 'got it'?
i'd argue a minority
Jean-Jacques Dubray
@jdubray
Feb 28 2016 21:26
yes, but the HN readers do not necessarily spend the right amount of time, nor can I claim to be clear enough to grasp the concepts in 10 min
I have to assume it was the same for React, it takes quite some time for most people to grasp the concepts
reactive, functional, TLA+/SM that's quite a lot
Milan Simonovic
@mbsimonovic
Feb 28 2016 21:30
my first impression was that it's some minor implementation issue and guess others also thought what's the fuss about
views subscribing to model's events or model initiating rendering
brusand
@brusand
Feb 28 2016 21:33
Views subscribing on states évents ?
This message was deleted
Jean-Jacques Dubray
@jdubray
Feb 28 2016 23:06
sure, that works too, that's what I call "wiring".