uranther
The SAM (State - Action - Model) pattern - General Discussion, Blog Posts, Wiki
SAM is a new reactive/functional pattern that simplifies Front-End architectures by clearly separating the business logic from the view and, in particular, strictly decoupling back-end APIs from the Front-End. SAM is technology independent and as such can be used to build Web Apps or Native Apps. It is also protocol independent and can be implemented over HTTP, WebSockets…
Creator: @jdubray
Gitter chat: https://gitter.im/jdubray/sam
SAM is a pattern that aims at replacing the MVC pattern. If you are already familiar with MVC, you should be able to make an easy transition to SAM.
There are two main differences between MVC and SAM. First, SAM is reactive, while MVC is generally implemented in an interactive way. Some attempts have been made at implementing it in a reactive way, however, SAM is not just a reactive implementation of MVC. Second, SAM introduces the concept of State as a mechanism to further decouple the View from the Model and treats the view merely as a “State Representation”.
Articles
Examples
- sam-tic-tac-toe
- SAM Lambda — SAM Lambda is a boiler plate project that implements the SAM pattern in AWS Lambda using DynamoDB to manage application/session state
Temporal logic of actions (TLA)
Articles
-
Temporal logic of actions (TLA) is a logic developed by Leslie Lamport, which combines temporal logic with a logic of actions. It is used to describe behaviours of concurrent systems.
-
… is a formal specification language developed by Leslie Lamport. It is used to design, model, document, and verify concurrent systems. TLA+ has been described as exhaustively-testable pseudocode and blueprints for software systems.
TLA+ is based on the idea that the best way to describe things formally is with simple mathematics, and that a specification language should contain as little as possible beyond what is needed to write simple mathematics precisely. TLA+ is especially well suited for writing high-level specifications of concurrent and distributed systems.
INDIRECT
Presentations
Academic Papers
See The Writings of Leslie Lamport for a full list of publications from this researcher.
“Programming languages provide no well-defined notion of a program step”
“State machines provide a framework for much of computer science. They
can be described and manipulated with ordinary, everyday mathematics”
- Model Checking TLA+ Specifications (1999)
- Temporal logic of actions (1994)
- Specifying Concurrent Program Modules (1983)
- ‘Sometime’ is Sometimes ‘Not Never’ (1980)
- A New Approach to Proving the Correctness of Multiprocess Programs (1979)
- The Implementation of Reliable Distributed Multiprocess Systems (1978)
- Proving the Correctness of Multiprocess Programs (1977)
Books
- Specifying Systems: The TLA+ Language and Tools for Hardware and Software Engineers
- TLA+2: A Preliminary Guide
- Specifying Concurrent Systems with TLA+
Related architectures
Trending in Wikis
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #elixirconf-us
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex











First 10 of 48 Posts!
gregvaughn
Interesting. This is the first time I heard it called SAM. I first heard about it as the Reactor model, or even “The Elm Architecture”
StefanHoutzager
Because Dubray has some critique on elm and says that an alignment with SAM would make it stronger I posted a question in an elm discussiongroup: Redirecting to Google Groups
jdubray
What’s missing in modern frameworks like Elm is the notion of a “Step” you just cannot arbitrarily process events, that is the problem. SAM suggests that a “step” (in response to an event) is composed of three phases: propose, accept and learn. When Elm issues a series of tasks to run some effects, it misses the essence of state mutation.
SAM is based on TLA+ semantics which introduce a new way to look at state machines, a lot closer to the way we write every day code (as opposed to traditional semantics like tuples (S0,A,S1). TLA+ provides enough structure without the burden of traditional state machines.
Happy to continue the discussion if you’d like.
rvirding
Shouldn’t the model and the state be one? Which states you have and transitions between them is completely defined by the model so splitting them seems strange.
But I may have misinterpreted the meaning of state and model.
Robert
StefanHoutzager
Mr. Dubray, I would love to get some more explanation about your graphql critique here: Api for an SPA - #4 by benwilson512.
Thanks for joining the discusion (on the elm forum also)!
jdubray
I’d prefer if you call me JJ.
Disclaimer, I was one of the original author of the SDO specification (Service Data Object- http://www.oracle.com/technetwork/testcontent/sdo-specification-java-v2-131073.pdf). I also worked for companies like Object Design (Object and XML Database) and built some solutions with products like MetaMatrix (now part of JBoss)
So, I am certain that GraphQL can solve a class of problems. I am sure it does wonders to Facebook because they can align their entire back-end to play nicely with GraphQL but this is not true of everyone. Stitching a complex back-end to GraphQL will always be the problem like it was for SDO or MetaMatrix. The other problem is more fundamental, data is relational and not “navigational”, no matter how you look at it and as soon as you start distributing it, you’ll run into performance issues each time you’ll need to perform joins across system boundaries. There is simply no way around it.
So again, I am certain it works well for Facebook, but it will fail entirely in the enterprise. You just can’t fight the relationality of data.
mkunikow
Ok I agree that GraphQL not always be prefect match. But what about the case you can have full control of backed and you can easy write back end as GraphQL?
Another solution for complex backed is BFF.
Anyway developers are moving away to handle different endpoint REST services in client and prefer to have some simplify/more optimized solutions. Imagine if you have 20 different REST endpoints you need to handle in mobile app. This is nightmare.
For me interesting alternatives to REST:
jdubray
David Fall has created a SAM sample using FireBase, it’s really good. We are currently discussing it on Gitter
https://github.com/509dave16/sam-tic-tac-toe
gitter.im/jdubray/sam
jdubray
Yes, that was exactly the problem I was trying to solve with SAM. This problems comes mainly from templates and databinding (1 API per screen/view)
That being said, weaving API calls in React is a real nightmare, a complete after thought in their programming model.
With SAM, APIs are hidden behind the model and the actions, so that you can use coarse grained APIs, up to direct persistence of the model in a document oriented database. I wrote an AWS Lambda / DynamoDB sample if you want to take a look.
mkunikow
Sure I will check with pleasure
Last Post!
jdubray
Well at some point you have to mutate something, making the application state immutable is what buy you nothing in terms of managing mutability. Let’s compare:
with:
access(m = accept(m, proposal))what’s the difference? a big malloc?
If X is a problem f(X) is rarely a solution, nor X$, not to mention, new X(). You probably need to dig a bit deeper than putting a big function box on some bad code to make it behave properly.
If you spend some time looking at TLA+ / Paxos and make an attempt to make mutation a first class citizen of your programming model, perhaps you’ll understand what I mean, otherwise, it looks like we’ll have to agree to disagree.
That being said, and quite strangely to be frank, Erik never talks about TLA+… I saw him mentioning it once in one of his talks telling the audience that he’ll have to learn about it, but he didn’t elaborate in any way.