Mraiih
Hello people,
I am a junior Rubyist and actually learning Elixir for fun. While I was learning some OOP design patterns for my job, I was wondering: “What about Elixir, functional and concurrent programming?”
I always see things about the Gang of Four, OOP, popular stuffs like that, but for FP, I came across this image:
I know design patterns came to resolve some common problems in OOP, but I suppose FP isn’t perfect and some problems can occur as well
Can anyone shed some light on this subject? And share some resource if needed?
Thanks a lot ![]()
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Aludel - LLM Evaluation Workbench
Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming












First Post!- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
kokolegorille
There are design patterns, but they are different.
One video I liked when switching from Ruby to Elixir is…
OTP is also a guide to good design with processes. It is worth learning.
The FP side of Elixir and Erlang is pragmatic, You can have side effects everywhere, and You don’t have some tools others FP languages may have, like monad, functor.
UPDATE: Oh, by the way your image comes from this talk
Most Liked
dimitarvp
Bit of a rant, sorry. Skip if you are not in the mood for one.
I would challenge even that. I worked with Java for 8-9 years and I worked with it in its heyday (and I dropped it when it became too crazy and “programming” in Java was 80% writing XML and 10% writing
.propertiesfiles). The other 10% you maybe wrote some Java.Those “patterns” helped only insofar as everyone was using them and thus onboarding in other people’s code was accelerated and made easier. They didn’t help with much else otherwise. They were like 90% social norms and 10% legitimately helpful ways of manipulating data via standardized code that made it future-proof-ish.
I also believe the entire “patterns” wording is quite unfortunate and does not at all capture the idea. “Dependency inversion” is just “don’t just pass one of the 17 implementations of this contract as a parameter to the using function, you idiot, use configuration!” and nothing else. “Factory pattern” is more or less “you don’t know the internal invariants of this data structure so please use a dedicated creator function for it and don’t try to be clever by directly setting the fields yourself”. Etc.
These should be common sense and should not be called “a pattern”; more like “an engineering guideline”.
That whole terminology only serves to make guys in suits-and-ties feel special and label themselves as consultants and bill insane sums of money for scratching their beards in meetings. Change my mind.
(It’s going to be hard because I’ve seen how they work, closely, several times in my career, and was not impressed. Of course it could also be bad luck, sure.)
On topic: for FP I think #1 principle would be: make the thing you want to manipulate composable and pipe-able (reference:
Ecto.Query,Ecto.Multi,Stream). Make it so you can manipulate the thing and accumulate / modify state captured inside of it. Make it so this can be done by any function abiding to a certain contract. Finally, invoke a function that actually “executes” what this thing represents (likeRepo.transactionactually does all the DB operations accumulated inside anEcto.Multi; while at the same timeEcto.Multi.insertfunction does nothing but put a state/command inside theEcto.Multithat says “OK, when this Multi gets executed, we want to create this DB record”).I have very small amount of failures in my career (although they make up for it being hugely embarrassing!
) and the “patterns” thing very rarely clicked with me, or most teams I ever worked with for that matter. People just organically and iteratively find what works best for their project. Stuff like “hexagonal architecture” or “functional core, imperative shell” are in general very good ideas and are emergent properties of most projects. I do like them but they too are not universally applicable.
dorgan
Friendly reminder that while Elixir is considered a functional language, the lack of auto currying makes the majority of functional programming patterns very cumbersome to use and functional composition(h = g ∘ f) is very rare in idiomatic elixir code, and thinking of elixir as a functional language like the others sets the wrong expectations. Sure, they’re good as inspirations, but I don’t find much value in them in Elixir other than having the vocabulary to understand why flat_map is called flat_map.
I find the philosophy of Clojure, ie the idea of data > functions, and thinking of data transformations rather than function compositions, is more helpful(see Ecto’s Changesets, Plug’s Conn, Ecto’s Multi and so on for inspiration). I unfortunately don’t have a list of resources right now, I’d like to compile some at some point or write down my opinions sometime, but I just wanted to point that out
al2o3cr
I understand the sense that the image is trying to convey, but I don’t think it’s particularly fair: the left-hand side are concepts and the right-hand side are implementations.
If the left-hand side was also implementations, it would just be “objects, objects, objects, yep objects again, objects etc”.
If the right-hand side was also concepts, it would have lots of things (some of which have already been mentioned) - monads, pattern-matching, etc.
Some of the right-hand side wouldn’t even be different - for instance, it seems totally reasonable to call this an example of the strategy pattern, where
Enum.sortaccepts a module that defines acompare/2:Last Post!
McElaney
I’d recommend checking out posts from Functional Programming Design Patterns | F# for fun and profit
This talk on Micropatterns by Cameron Price is also worth a look https://www.youtube.com/watch?v=9uvp4h7gXHg