These are chat archives for jdubray/sam

25th
Jul 2017
Janne Siera
@jannesiera
Jul 25 2017 16:25

When you conflate proposal (the new values of the application state), the mutation and the state representation you create spaghetti code (not to forget NAP). That code is hard to debug and maintain. There is no reason it should be that way.

Why does this necessarily result in spaghetti code? I understand that the premise of SAM is "assignment is not mutation" and that it tries to solve this by containing mutation in a centralized place. But it is still not clear why it is such a sin to equate assignment and mutation.

In other words, Functions are good at creating proposals (an Action is a pure function)
Objects are good at encapsulating (application state), the Model is an Object, with a single method (closure ok)
Reactive programming is good at computing new values in reaction to changes in other values (dependencies between properties)

This is actually a great soundbite. I'm surprised I haven't seen this in any of your articles / online conversations yet. The model as an Object encapsulating application (!) state really resonates with me as I can relate it to 'classic' OOP. In this sense the chosen terms of State, Action, Model really prove to be a bit unintuitive to me, as I now think of the Model as the Application State (Object).

Could you remind me again where TLA+'s Control State (as opposed to Application State) fits into the SAM pattern?

Jean-Jacques Dubray
@jdubray
Jul 25 2017 16:32
It's spaghetti in the sense that proposal, mutation and state representation are not clearly delineated, no matter how good a developer you are, when you start mutating or computing the state representation when the proposal is not complete, you are bound to encounter some problems.
The classical state machine semantics (control state) are overarching. The "step" of the pattern provides a safe area to compute the control state (as part of the state representation) and with NAP you have pretty much all you need to implement state machines. Again, I'll never say it enough, I'll never recommend using the State-Action semantics, SAM's overall structure gives you "state-machine" semantics without the burden of defining every possible control states (which is not practical).
devin ivy
@devinivy
Jul 25 2017 17:39
@jdubray do you have some good fundamental reading on why by-the-book state machine semantics do not make for a good programming paradigm? i agree with it based upon experience, but i'm wondering where i can find some more info about that.
Jean-Jacques Dubray
@jdubray
Jul 25 2017 18:24
I think I'll have to go with Dr. Lamport's explanation: "the vast majority of (control) states" is irrelevant to the program", so you'd be creating a lot of boilerplate for no value at all.
I am not a specialist, but I have not see any formal study. I can ask on Twitter, I am connected to several computer science professors.
Jean-Jacques Dubray
@jdubray
Jul 25 2017 18:37
@jannesiera I am just trying to show that each programming model has merit and was often designed to solve specific problems, however, any of them taken individually appears to be incomplete. For instance the encapsulation provided by OOP if well off the mark when it comes to managing mutation properly (fragmented state, unsynchronized access...).
devin ivy
@devinivy
Jul 25 2017 18:42
@jdubray at the same time, it would be easy to misinterpret dr. lamport's other work to say that state machines are a good programming paradigm.
or maybe not even misinterpret, but cherrypick.
Jean-Jacques Dubray
@jdubray
Jul 25 2017 18:49
That's kind of the paradox, computation is about state machine, but it is not efficient to use (classical) state machine to model computations. The art is to find a programming language that allows to create the correct (underlying) state machine for the problem you are trying to solve.
As we mentioned in the article:
  • state machine can compute
  • you can reverse engineer the state machine behind any action based program
Is there a programming language / model that makes it easier to write correct programs that are easy to debug and maintain?
my concern with a lot of the programming paradigms is that they start really really far away from the state machine (function, object, stream, classical state machine...) and then the reality hit and you have to stitch a bunch of concepts that do not necessarily fit with your initial pure vision of what programming could be.
I have tried the best I can to show that there is something that's just not right when you say "everything is a function" or "everything is an object".
They introduce unnatural/fallacious boundaries to your code.
It looks cool (who would not think that "everything is a function" or even "everything is an object" isn't cool/believable/interesting/attractive?
Jean-Jacques Dubray
@jdubray
Jul 25 2017 18:55
but when you step back a second and you remember that "Much of computer science is about state machines"
Antanas A.
@antanas-arvasevicius
Jul 25 2017 18:56
but state machine is just one concept of many
Jean-Jacques Dubray
@jdubray
Jul 25 2017 18:57
@antanas-arvasevicius nope, "classical state machine" yes, but not "state machines". The problem is that we don't have a way to express the more general state machines that make up computation.
I have tried the best I can to show that we should leave the classical state machines behind. We should no longer think in those terms.
Antanas A.
@antanas-arvasevicius
Jul 25 2017 18:58
what I want to say, that modeling a solution to some problem some other concepts can be used for that
not only state machines
e.g. filter & pipes / streams
as in Akka Streams library
Jean-Jacques Dubray
@jdubray
Jul 25 2017 18:59
well, it would be more efficient, but I would argue that we would be able to reduce any computation to a state machine definition.
No matter how high the abstraction, it will always be possible to reduce it to a state machine.
Please note that I am never recommending to do that.
Antanas A.
@antanas-arvasevicius
Jul 25 2017 19:00
and state machine can be converted to turing machine
Jean-Jacques Dubray
@jdubray
Jul 25 2017 19:00
All I am saying is that when you start with a conceptual model where "everything is a XXX (stream, actor, function, object)" the gap with the underlying state machine is too big
Antanas A.
@antanas-arvasevicius
Jul 25 2017 19:00
if going more low level
but should / must this gap be closer to state machine?
Jean-Jacques Dubray
@jdubray
Jul 25 2017 19:00
sure if you want to. I am not even calling what a state machine is (incidentally, it could be the other way around, turing machine is a special case of state machines...)
Antanas A.
@antanas-arvasevicius
Jul 25 2017 19:00
and what is consequences if no
Jean-Jacques Dubray
@jdubray
Jul 25 2017 19:01
When you are too far from the structure of the underlying state machine, your code will be hardor to factor
especially when it comes to mutation and control state.
Antanas A.
@antanas-arvasevicius
Jul 25 2017 19:01
a question is if we must every problem express in state machine
Jean-Jacques Dubray
@jdubray
Jul 25 2017 19:01
I am never recommending to do that
Antanas A.
@antanas-arvasevicius
Jul 25 2017 19:02
it's like in math to say we must everything express in diff equations
devin ivy
@devinivy
Jul 25 2017 19:02
haha >.<
Jean-Jacques Dubray
@jdubray
Jul 25 2017 19:02
I am only recommending that when you come up with a programming model you have a reasonable lineage to the underlying state machine.
It seems that we create lots of programming paradigms without ever looking at it
and the main reason is because the gap with classical state machines is too wide
which is due to the fact that the underlying state machine is not a classical state machine
devin ivy
@devinivy
Jul 25 2017 19:04
by "classical" you mean what exactly?
Antanas A.
@antanas-arvasevicius
Jul 25 2017 19:04
but e.g. how FP paradigm fits in this view?
Jean-Jacques Dubray
@jdubray
Jul 25 2017 19:04
S1,A,S2
a graph of states and actions (Petri nets)
Antanas A.
@antanas-arvasevicius
Jul 25 2017 19:04
isn't the FP based on higher order functions and lamba calculus
devin ivy
@devinivy
Jul 25 2017 19:04
sure. how does that differ from just a "state machine"?
Antanas A.
@antanas-arvasevicius
Jul 25 2017 19:05
*FP paradigm
Jean-Jacques Dubray
@jdubray
Jul 25 2017 19:05
@antanas-arvasevicius that's my point is that all these cool programming paradigms have never been aligned with the underlying state machine. That's the job of the developer (good luck with that)
TLA (temporal logic of action) seem to offer another structure for "state machines". One that is based on mathematics.
"functions" are just one concept of mathematics.
Antanas A.
@antanas-arvasevicius
Jul 25 2017 19:06
but FP languages are more aligned not for developers, but for mathematicians, they want to express something declaratively
without actually thinking how it will be solved in hardware
Jean-Jacques Dubray
@jdubray
Jul 25 2017 19:07
Actually if you read a bit about Lambda Calculus, it's a great theory, but it does not seem to address "computation", there is a difference between computation and calculus.
I am not disputing that some abstraction can be good at solving some classes of problem, I am only arguing that a programming paradigm must be mapped (more or less) to the underlying state machine.
When you don't do that, you rely on the developer to do it, day in and day out, and each developer will do it very differently.
Antanas A.
@antanas-arvasevicius
Jul 25 2017 19:08
but this will map every problem to a state machine
Jean-Jacques Dubray
@jdubray
Jul 25 2017 19:08
That's highly inefficient
@antanas-arvasevicius absolutely not
Antanas A.
@antanas-arvasevicius
Jul 25 2017 19:09
or do you mean only theoretically
Jean-Jacques Dubray
@jdubray
Jul 25 2017 19:09
If I don't tell you I mapped SAM to the structure of a state machine, you would never know.
not theoretically, it has to be very concrete, but you feel this is odd, because you are thinking in terms of classical state machine
that's not what I mean
Antanas A.
@antanas-arvasevicius
Jul 25 2017 19:11
what I know from university is deterministic FSM and non-deterministic FSM
as I understand from you it's classical state machine
Jean-Jacques Dubray
@jdubray
Jul 25 2017 19:11
yes
Lambda calculus provides a theoretical framework for describing functions and their evaluation. Although it is a mathematical abstraction rather than a programming language, it forms the basis of almost all functional programming languages today. An equivalent theoretical formulation, combinatory logic, is commonly perceived as more abstract than lambda calculus and preceded it in invention. Combinatory logic and lambda calculus were both originally developed to achieve a clearer approach to the foundations of mathematics
Lambda Calculus or combinatory logic is one step above state machines
As we all know "state" is very hard to manipulate. All I am suggesting is that instead of punting blindly on state management, is to focus on it.
It is unfortunate that we were all taught "classical state machines"
Jean-Jacques Dubray
@jdubray
Jul 25 2017 19:18
I really want to emphasize: "Lambda calculus provides a theoretical framework for describing functions and their evaluation"
Antanas A.
@antanas-arvasevicius
Jul 25 2017 19:18
but all FP is based on theoretical proofs
if we would analyze FP code it doesn't matter how exactly compiler / interpreter do the computations
If looking from the FP programmer perspective
btw. "Abstract State Machines" by Yuri Gurevich isn't a close to SAM?
Abstract.
Conventional computation models assume symbolic representations of
states and actions. Gurevich’s “Abstract-State Machine” model takes a more li-
beral position:
Any
mathematical structure may serve as a state. This results in
“a computational model that is more powerful and more universal than standard
computation models” [5].
We characterize the Abstract-State Machine model as a special class of transition
systems that widely extends the class of “computable” transition systems. This
characterization is based on a fundamental Theorem of Y. Gurevich
Jean-Jacques Dubray
@jdubray
Jul 25 2017 19:25
it seems close since it has a "next-state" function
the similarities with the three-letter-achronym is interesting!
Jean-Jacques Dubray
@jdubray
Jul 25 2017 19:27
I can't parse the math as fast,
Antanas A.
@antanas-arvasevicius
Jul 25 2017 19:28
Yeah, need more study on that ASM
but question why it's still not widespread if it is so cool
Jean-Jacques Dubray
@jdubray
Jul 25 2017 19:29
I know lots of crap that's popular
Antanas A.
@antanas-arvasevicius
Jul 25 2017 19:29
:))
Jean-Jacques Dubray
@jdubray
Jul 25 2017 19:29
I am not sure there is a correlation between correctness and popularity
it seems the opposite these days
Antanas A.
@antanas-arvasevicius
Jul 25 2017 19:30
right :D
today thinking is - if a big company uses X then if we use X we'll become as big as that company
Jean-Jacques Dubray
@jdubray
Jul 25 2017 19:32
Napoleon said: "La passion des hommes pour le merveilleux est telle qu'ils sont prêts à lui sacrifier la raison"
Antanas A.
@antanas-arvasevicius
Jul 25 2017 19:32
actually it's paradox that project managers and business owners dictates what technologies must be used on the project
Jean-Jacques Dubray
@jdubray
Jul 25 2017 19:32
~ the passionate attraction of man for the marvellous is such that they are ready to sacrifice reason"
Antanas A.
@antanas-arvasevicius
Jul 25 2017 19:32
I've seen many requirements just because "this technology is great we must use that on this project"
hehe
Jean-Jacques Dubray
@jdubray
Jul 25 2017 19:33
For me, my journey has been "state management" everywhere I turned too for the last 25 years, "state management" was left at the liberty of the developer.
stranger, isn't it?
Antanas A.
@antanas-arvasevicius
Jul 25 2017 19:35
but somehow we are managing it
:)
devin ivy
@devinivy
Jul 25 2017 19:36
haha yeah sort of :D
Jean-Jacques Dubray
@jdubray
Jul 25 2017 19:36
yes! so why not manage it more consistently?
Antanas A.
@antanas-arvasevicius
Jul 25 2017 19:36
but isn't OOP was invented for that?
excluding "code reuse", "extensibility" myths
Jean-Jacques Dubray
@jdubray
Jul 25 2017 19:36
not quite, OOP introduced the concept of encapsulation because it was too hard to manage global state
devin ivy
@devinivy
Jul 25 2017 19:36
one thing i don't find OOP to be particularly attractive for is... state management
Jean-Jacques Dubray
@jdubray
Jul 25 2017 19:36
it's kind of the "monolith->microservices" of the time
Antanas A.
@antanas-arvasevicius
Jul 25 2017 19:37
:D
Jean-Jacques Dubray
@jdubray
Jul 25 2017 19:37
I am surprised Martin Fowler was not involved
in this debacle
@devinivy my point exactly
Very few times in the history of our industry we actually set out to solve that problem head on
It's been more like punt or sweep under the rug
Antanas A.
@antanas-arvasevicius
Jul 25 2017 19:39
wait a sec, just reminded me one requirement from client to use ecommerce "Spryker platform" and use only microservices, but that Spryker's authors says, that microservices is very dificult and they manage to do that platform as monolith, but use modules, and created some fictive module system on PHP with strict convention how to make everything looose coupled
Jean-Jacques Dubray
@jdubray
Jul 25 2017 19:40
That's kind of my point on "artificial boundaries" all these up-in-the-air concepts like everything is a function, actor, stream, object... create unnatural boundaries that you have to fight.
Data is relational, there is no way, absolutely no way around it
devin ivy
@devinivy
Jul 25 2017 19:41
@jdubray i think it's a really important point to make that using classical state machines, as you call them, is not a realistic way to manage an entire application's state. there are real professionals advocating for it, but i find it hard to imagine they actually do program around classical state machines in practice. see https://medium.com/@asolove/pure-ui-control-ac8d1be97a8d
Jean-Jacques Dubray
@jdubray
Jul 25 2017 19:42
ouch this article hurts
devin ivy
@devinivy
Jul 25 2017 19:42
not to mention all the terminology surrounding e.g. redux evokes the idea of classical state machines.
Jean-Jacques Dubray
@jdubray
Jul 25 2017 19:43
they do?
devin ivy
@devinivy
Jul 25 2017 19:43
i think naively it does.
Jean-Jacques Dubray
@jdubray
Jul 25 2017 19:43
it's like everything, all these concepts have merit (cSM, function, object...) but they are incomplete.
it's the incomplete part that creates the problem
you'll start seeing frameworks
anti-patterns
Antanas A.
@antanas-arvasevicius
Jul 25 2017 19:44
that's why Exceptions was created :D
Jean-Jacques Dubray
@jdubray
Jul 25 2017 19:45
that's the absolute wrong concept!
we should have safety conditions
not exceptions
(you are in an invalid state)
devin ivy
@devinivy
Jul 25 2017 19:46
p.s. on a positive note, i wonder if you would find this library to be useful @jdubray @foxdonut https://github.com/ccorcos/reactive-magic
Antanas A.
@antanas-arvasevicius
Jul 25 2017 19:46
yeah, but I think exceptions are perfect fit for that "incomplete/unknown state" problem
maybe they were made for that
Jean-Jacques Dubray
@jdubray
Jul 25 2017 19:46
@devinivy yes, great for the state function!
devin ivy
@devinivy
Jul 25 2017 19:47
i love that update() essentially takes a mutation an an argument :)
Jean-Jacques Dubray
@jdubray
Jul 25 2017 19:47
@antanas-arvasevicius that's really the problem, we throw concepts into the air, then there are big gaps, then we fill them with whatever concept, without ever trying to understand what is going on.
yes, but as you can see ;-) it's not a mutation, it's an action, or if it is a mutation, they cobble it with an action
that's really my point, we have three concepts: Action, Model, State and we somehow always create monadic or diadic conceptual models.
devin ivy
@devinivy
Jul 25 2017 19:50
yes i see that in the example. but the actual API lends itself to authoring mutations as functions that can be passed to update().
Jean-Jacques Dubray
@jdubray
Jul 25 2017 19:51
sure, I understand what you are saying, but imagine the developers discovering the library, how will they code it? a mutation or an action?
devin ivy
@devinivy
Jul 25 2017 19:54
i agree the library itself isn't very prescriptive there
Jean-Jacques Dubray
@jdubray
Jul 25 2017 19:56
worse, people might like it so much that they use it to mutate state!
sorry, have to go.
devin ivy
@devinivy
Jul 25 2017 19:56
later! :wave: nice chattin
Jean-Jacques Dubray
@jdubray
Jul 25 2017 19:56
:+1:
Antanas A.
@antanas-arvasevicius
Jul 25 2017 20:00
bye