These are chat archives for jdubray/sam

8th
Apr 2017
Marcus Feitoza
@mfeitoza
Apr 08 2017 03:26
@dagatsoin yes a think this is some approach
Paolo Furini
@pfurini
Apr 08 2017 13:39
@edmulraney what are automatic actions in React? sorry but the only thing I've done with react til now is buying a good book and reading the first chapter.. :smile:
Paolo Furini
@pfurini
Apr 08 2017 13:46
and yes @edmulraney and @jdubray , the naming difference of the various moving parts IMHO is the major source of debate out there.. and that's the problem in every young field of study. Even in FP, that's not so young, they use many "strange words" that are in essence simple concepts that everyone maybe already knows.. (sorry to FP aficionados reading this)
Jean-Jacques Dubray
@jdubray
Apr 08 2017 13:46
@pfurini The React community has proven something we long suspected in our industry, you are always one library away from having designed the perfect framework.
Paolo Furini
@pfurini
Apr 08 2017 13:51
the perfect framework is the one which is better aligned to your way of doing things.. if one needs to battle against the framework every day, better to change direction, it doesn't matter which one
if your best framework is no framework, well.. go for it
Jean-Jacques Dubray
@jdubray
Apr 08 2017 13:55
sure, to be fair, React opened a new path in our industry, but to your point, a framework is like shackles. It creates a dependency that will very quickly slow you down as you need to get around what it cannot do for you. It's true of any programming model as well, including SAM, FP, OOP.
It's truly about applying the best tool for the job. We can see today how limited was OOP as a programming paradigm. We are discovering FP, but the same will happen to it.
This is my original post on the SAM pattern
Jean-Jacques Dubray
@jdubray
Apr 08 2017 14:00
I showed this picture before, but you may not have see it
There are four concepts that seem to be irreducible and independent: Types, Action, States and Relationships. Most programming paradigms tend to ignore one or more. OOP is centered on Type and attach actions to classes (makes no sense). FP is centered on actions, and use Clojures for Types (what is a Clojure if not a Class?).
FP is better than OOP, no question, but it stills ignores State and Relationship.
Even SQL ignores Relationships! (kind of), a relationships is reified as a property of a type.
Jean-Jacques Dubray
@jdubray
Apr 08 2017 14:06
State is ignored by pretty much everyone, yet it is fundamental to everything we do. That is the problem. At a minimum SAM gives you a structure to better manage State. It keeps it separate from Types (Model) and Actions, with the State function and Nap.
Paolo Furini
@pfurini
Apr 08 2017 14:11
agree with you, my own frustrations made me wonder if a better way than my good old OOP paradigms existed.. so I started exploring FP in various forms, at the same time trying to reason if they tackled the problem I faced at full scale
Jean-Jacques Dubray
@jdubray
Apr 08 2017 14:16
IMHO, the only way to make it work is position these four concepts. When you apply strict FP, you'll face the full force of not having any place to land state. At least with OOP, you had some reasonable way to position actions, state and relationships. The problem was more the center of gravity of OOP.
FP sounds appealing today because it fixes an approximation that has become harder to deal with the complexity of the code: actions cannot modify state. The way FP does it is via immutability. Pure functions provide a natural boundary where you can update the state and then when you are done everyone else sees it.
But immutability comes at a big cost, and in the case of FP it's fragmented. Elm/Redux have introduced a single state tree, which is preferable, but then you pay the full price of immutability.
Paolo Furini
@pfurini
Apr 08 2017 14:19
Yes, and the first incidental benefit is better handling of highly concurrent tasks
Jean-Jacques Dubray
@jdubray
Apr 08 2017 14:20
Yes, you have no choice these days, even though JavaScript is single threated, logically, as soon as APIs are involved, programs behave with some level of concurrency. You just cannot ignore it.
Paolo Furini
@pfurini
Apr 08 2017 14:21
Single state trees are wrong in the first place. They are a great way to reduce the learning curve, and initial development, but they are not scalable
Jean-Jacques Dubray
@jdubray
Apr 08 2017 14:21
That's why everyone is looking for a composition mechanism.
Paolo Furini
@pfurini
Apr 08 2017 14:22
exactly
Jean-Jacques Dubray
@jdubray
Apr 08 2017 14:22
What we are really talking about is an isolation mechanism, single state tree is just a way to achieve it.
albeit not very scalable
Paolo Furini
@pfurini
Apr 08 2017 14:25
Regarding the price of immutable data, a big role is played but the underlying platform. I mean, in the BEAM where the garbage collection is a low cost operation, and does not pause execution, even large state trees are not such a big concern
But that's only in terms of performance. In terms of overall architecture, I prefer small isolated and interconnected pieces that orchestrate work together, a micro container architecture where the app is only a container of containers
Paolo Furini
@pfurini
Apr 08 2017 14:30
AWS Lambda proved that this is a successful and infinitely scalable approach
Jean-Jacques Dubray
@jdubray
Apr 08 2017 14:58
but Lambda is stateless...
The state is handled either in a cache or in a back-end, and there is quite a price to store it or retrieve it.
Now that Microservices have taken off, people are now struggling with coordination and consistency...
there is no free lunch
again, there are four irreducible concepts in programming, you can decide to ignore gravity but you are not going to fly really far...
It doesn't mean that building an airplane is easy, but there are things you just can't ignore
I can jump around and pretend I am flying.
Or I can throw an apple 20 meters away and tell everyone, see, the apple is flying.
Jean-Jacques Dubray
@jdubray
Apr 08 2017 15:06
OOP, FP, SAM,... are just one way of articulating these four concepts
Paolo Furini
@pfurini
Apr 08 2017 15:13
When used properly.. OOP is the most misused/abused one. When it is taught like "put some state in a class, protect it from the outside, call methods to manipulate it, then just add patterns", what you get is a crowd of developers that start to write some decent code only after many and many years of mistakes
Jean-Jacques Dubray
@jdubray
Apr 08 2017 15:17
exactly, core programming concepts tend to be abused (such as encapsulation and inheritance) because people don't understand the foundation behind the programming model, then patterns and libraries show up and before you know it you have an ocean to choose from.
Just got that on Twitter
blob
sorry I have to laugh.
The foundation will never change, it's like saying that physics can be described with mass, light, energy and force, but Optics or Chemistry is enough to describe everything.
Of course, there is Quantum Physics below these four concepts, but the mass, light, energy, force paradigm is hard to break when you describe things at our scale. Even relativity didn't break it. It was just a different way to combine these four concepts, compared to Newtownian physics.
Jean-Jacques Dubray
@jdubray
Apr 08 2017 15:22
It's the same here, someone says let's use FP, then they have to stitch lots of libraries and patterns together because they stumble on problems after problems.
Radosavljevic Slobodan
@radosavljevic
Apr 08 2017 15:55
@jdubray What books would you recommend on programming concepts, especially something that deals with STAR? Videos and articles would be great too. Could you briefly explain each of the concept? Thank you!
Paolo Furini
@pfurini
Apr 08 2017 16:07
@jdubray When you wrote this article http://www.ebpml.org/blog15/2015/06/sam-the-state-action-model-pattern/ you were enthusiastic about React, and using it along side Flux+STAR supporting library written in JS.. I missed the point, something changed since then and you're recommending/enforcing something different..? Sorry, but reading all of this material at once creates a lot of confusion in the uninitiated..
If I were to start a project from scratch, like building a data-driven SPA application , what's the approach you'd recommend today for a fast start (at least for a PoC)?
I mean, the STAR library you have on bitbucket, a custom implementation of the SAM pattern, something else written by someone you know or trust?..
Jean-Jacques Dubray
@jdubray
Apr 08 2017 17:16
then you hit the wall of using React when you need to stitch API calls. My enthusiasm came from the new functional HTML paradigm, it felt so new and right, when compared to manipulating the DOM. Then you realize that a react component is just html = f(properties), everything else is just garbage, but you discover that one thorn at a time.
I am not in the position to recommend anything, it really depends of your context. If you want to build your resume and look like a rock star that just climbed Mount Everest, then choose React.
If you are a big IT shop and you want something that all your developers will be able to learn and master, then choose Angular2/3/4 whatever the number of the day is.
If you are pragmatic and enjoy your craftsmanship, then use vanilla.js, a good theme and a small dose of JQuery where view components would not work as V = f(M).
Paolo Furini
@pfurini
Apr 08 2017 17:22
When I looked at Angular 2 in its first iterations, it didn't sound so "right" to me
Jean-Jacques Dubray
@jdubray
Apr 08 2017 17:23
As I said, it depends, I can speak for experience, I just finished a big Angular2 project for a Fortune50 company and it went without a scratch. Everyone in their developer pool can master it.
Paolo Furini
@pfurini
Apr 08 2017 17:23
But maybe I was looking at it with the wrong attitude at that time..
Jean-Jacques Dubray
@jdubray
Apr 08 2017 17:24
Now can you do cool things with it? maybe not. A simple date picker was a challenge, but we just got it to work for what we needed.
I wrote the STAR library, I see myself as a back-end guy with a strong knowledge of API orchestration (stateful). After working for about 15 years in building orchestration languages like BPEL (not to mention virtual query languages like GraphQL) I discovered TLA+ and I realized that I no longer needed a dedicated orchestration language, I could orchestrate APIs in Java or JavaScript. That was a turning point for me. SAM/TLA+ was the way forward. I could even explain why nothing worked with OOP and why FP will not work either.
Now, it's just me, I am just nobody, but I have been around enough to show why something works and why something doesn't.
Paolo Furini
@pfurini
Apr 08 2017 17:27
So you used that same library (I mean the one on bitbucket) in that NG2 project, or is it only a PoC?
Jean-Jacques Dubray
@jdubray
Apr 08 2017 17:31
The bitbucket library is just for API orchestration. No front-end.
The best place for Angular2 is GitHub. The dashboard I showed you earlier
Conceptually it's very simple.
I set the video to start where I explain how SAM works with Angular2
Paolo Furini
@pfurini
Apr 08 2017 17:35
What about the javascript STAR repo? I've seen the apicall example, using the component pattern to make api calls.. is that something you use in the wild?
The library come with several samples (including WebSocket).
You can even use it from the browser!
When you have complex API orchestations you want to drive from the UI, not fully recommended, but sometimes you have no choice.
Super easy to use.
I think the problem you'll have if you are an experienced Web developer is that the UX of modern Web frameworks is not aligned with what you are currently seeing as the state of the art with JQuery. I would not be surprised if in the end you prefer vanilla.js + jquery.
Paolo Furini
@pfurini
Apr 08 2017 17:39
So that's something you use on the nodejs side most of the time, but that can be used on the client too
Jean-Jacques Dubray
@jdubray
Apr 08 2017 17:39
It's just today, if you use raw vanilla.js, you'll hit the SPA wall, JQuery won't really help you there. The bottom line is that you cannot build complex SPA in raw vanilla.js
yes! I am a big fan of JavaScript everywhere, Lambda where you can.
I created a SAM micro-container that works in the browser, node.js and lambda too!
You can't do SPA with DOM manipulations and you can't build the kind of UX you want with Angular2 (and even React :-))
But the react community will claim I am just a troll.
When you factor in complex problems like API orchestration (for SPA), it quickly becomes mission impossible. It's interesting that SAM offers an elegant solution for all of them, I know why, but most people will dismiss it.
It works because both SPA and API Orchestrations are highly stateful...
Paolo Furini
@pfurini
Apr 08 2017 17:44
That was the reason I preferred aurelia at the time.. the fact it was using a template system (and a very efficient one), with a light virtual dom implementation, makes possible implementing the same rich interactions that jQuery provides.
but then I found that a template system is not the correct choice, as you pointed out several times
Jean-Jacques Dubray
@jdubray
Apr 08 2017 17:45
Yes, that is a multidimensional problem and you have to be careful in picking the right solution for you.
I got it to work with Angular2
Marcus Feitoza
@mfeitoza
Apr 08 2017 17:46
@jdubray I ready some of your critiques about REST.
I think REST fits well for simple CRUD, but start become mess when need to deal with lot of actions in one record.
What do you recommend?
Jean-Jacques Dubray
@jdubray
Apr 08 2017 17:46
But, it's really about how do you use a template system. The core problem is that the V->M binding is wrong. You need to convert that binding into events.
It's not wrong, it's incomplete...
blob
You guessed it, what's missing is actions and state...
It ironic, since this is called the rep... State ... transfer
The reason it only works for CRUD is because it's centered on resources (~types, very anemic types, unlike objects)
REST is missing actions, the actions (HTTP verbs) match the lifecycle of a ... web page or crud.
When one of the four STAR concept is missing, you are doomed, it will not work period. It's like trying to fly without accounting for gravity or fluid mechanics.
Again, that's what the RESTafarians have done for a while until people lost inteReST.
Jean-Jacques Dubray
@jdubray
Apr 08 2017 17:52
You just cannot go around it, no matter what you do.
As I said, with react it felt new and different, that's until you understand how they manage state. You cannot manage state inside a component. Little by little they chipped away at their component model, to reduce it to a simple function, then moving state management outside with Flux and Redux, introducing... actions and stores.
That move was not surprising, what it wrong is aligning it with FP.
With STAR I can pretty much predict what's going to happen with any framework / technology.
Paolo Furini
@pfurini
Apr 08 2017 17:56
I don't get why it's wrong trying to implement STAR using FP
Jean-Jacques Dubray
@jdubray
Apr 08 2017 17:56
I am just saying that FP alone is not aligned with STAR.
Marcus Feitoza
@mfeitoza
Apr 08 2017 17:56
I got, I still working in my wiring with Mithril.
Yesterday I have enlightenment when you said "don't think like components but like building blocks" and everything becomes more clear to me.
Jean-Jacques Dubray
@jdubray
Apr 08 2017 17:57
People marvel at Clojures but it's just a Class! just a different syntax.
@mfeitoza :+1:
Marcus Feitoza
@mfeitoza
Apr 08 2017 17:58
Later I will read your article and start implement.
What do you think is better for urls:
/invoice?action=newPayment
json: {data}
or
/invoice
json: {newPayment: {data}}
Or another approach?
Jean-Jacques Dubray
@jdubray
Apr 08 2017 17:58
@pfurini Show me how people manage State and Relationship in FP, then we'll talk again.
Paolo Furini
@pfurini
Apr 08 2017 18:00
I'm not saying it's done right now, I'm saying it should be feasible and aligned with the core FP principles
Jean-Jacques Dubray
@jdubray
Apr 08 2017 18:01
@mfeitoza There are two opposing points of view:
1/ authorization (actions are easier from an authorization perspective)
2/ self-standing payloads which travel well through processing pipelines
I would never use query parameters, perhaps just for queries, but even as a query language they don't work well
@mfeitoza you should not be afraid to use actions (verbs) in URLs
forget REST
@pfurini everything is possible
the problem is that when you don't know where you are going, you may never end up reaching your destination.
The FP community is a bit like that today. They think that immutability is non-negotiable. Good luck with that.
Paolo Furini
@pfurini
Apr 08 2017 18:03
that's the main point here, too many options, but one needs to be pragmatic at the end of the day..
Jean-Jacques Dubray
@jdubray
Apr 08 2017 18:04
All the paths lead to Rome... but you still need to know you want to go visit Rome!
Immutability to FP what inheritance is to OOP, a great concept!
Paolo Furini
@pfurini
Apr 08 2017 18:06
But I really think that immutability is the right choice, but not alone obviously.. at least on the server side, and when programming for high concurrency with potentially no locking
Marcus Feitoza
@mfeitoza
Apr 08 2017 18:06
@jdubray thank you again.
Jean-Jacques Dubray
@jdubray
Apr 08 2017 18:07
@mfeitoza you are welcome
Paolo Furini
@pfurini
Apr 08 2017 18:07
like everything, the right tool for the job, FP is not a swiss-army knife
Jean-Jacques Dubray
@jdubray
Apr 08 2017 18:07
@pfurini the way to look at it is that actions cannot mutate (application) state, that is the true way to express what people call immutability.
Immutability is just one way to achieve that purpose.
When you industry don't even want to agree on what an action is, how can you build something stable underneath?
You have to think in terms of first principles. Immutability is like a 2nd or 3rd principle.
FP is using a bazooka to kill a fly.
It works, but it doesn't scale very well.
Paolo Furini
@pfurini
Apr 08 2017 18:10
Yes, what I mean for immutability is not like a language choice, that's an implementation detail. What's wrong in many OOP architectures is that they spread mutations everywhere, and that becomes a nightmare from many points of view, one of them is parallel execution and work distribution
Jean-Jacques Dubray
@jdubray
Apr 08 2017 18:18
Yes, that's a first principle analysis
Jean-Jacques Dubray
@jdubray
Apr 08 2017 18:45
That's why actions create proposals in SAM, then you can decide how the proposal mutates state.
Jean-Jacques Dubray
@jdubray
Apr 08 2017 19:20
@pfurini you may also enjoy this post, an essay on revisiting the Conway Law, to get a perspective on the current paradigm shift in Software Architecture, and why selecting properly your Web framework is so critical on an "activity-oriented world"
It's not the UX, it's really about being able to build meaningful "edges", something we are not really accustomed to. The current thinking is just UI -> UX, but UX is not enough -> AX (Activity Experience).
Rodrigo Carranza
@DrecDroid
Apr 08 2017 22:08
Just one to point something, If you try to do an SPA that plays well with SEO you will have really hard times dealing with client/server side rendering trying to have the same view rendered in the client and the server. I'm not saying It's impossible but It will make your app become the most complex beast you ever worked on. Just SPA + SAM and vanilla js is super easy to deal with