mmport80
OTP is Bad
Flamebait-y title, but Joe Armstrong doesn’t use OTP, so I am not in uncharted territory.
But… I have been thinking (dangerous).
I read a blog post a while ago, by a Lisp guy, who said that programming patterns are bad, because they are used to patch language weaknesses.
I imagine, in Lisp-world, patterns are packaged into nice little macros and all is good in the world because Lisp is flexible like that.
Perhaps too, this is where Elixir could really take a leap beyond Erlang.
By packaging OTP behaviours into macros.
Then again, perhaps the analogy is completely wrong, because behaviours aren’t really design patterns in the first place (although, I feel they aren’t far away).
Nevertheless, if I am making a little sense, I would love to hear some more experienced people’s views.
Most Liked
Qqwy
I had a very interesting conversation with a fellow developer a while back. He has a background in building engineering, and told me the following story:
- Architect designs a building.
- The building engineer tells the architect “you really need to make this column three times as wide, or otherwise the roof will collapse”.
- The architect says: “Aww, but it ruins my Feng-Shui”.
- The final building is constructed from the compromises that the architect and the building engineer agreed on.
- People believe that the whole building was built single-handedly by the architect.
He said that what people in Computing Science call ‘design patterns’ (probably since the famous ‘design patterns’ book written by the ‘gang of four’) are actually ‘structural patterns’: “build the column this way or the roof caves in.”.
As such, they have nothing to do with beauty, but everything with practicality (which, in computing science, translates to speed/memory efficiency, ease-of-understanding, ease of refactoring).
Many programmers boast that “they solved problem A by using patterns X, Y and Z”, but that is useless. Patterns are something to recognize and use when it is useful to do so, not something to boast over or to cram as many as possible in your application of.
In the end, the main use of these named patterns is that two developers can have a conversation about a possible solution for a problem, and easily describe to each other how these work in general terms, just like two architectural engineers might converse and say: “to prevent this wall from collapsing, we could use a buttress.”
Tl;Dr: do not use patterns to solve a problem. do solve a problem by using patterns.
Patterns are good nor bad, but programming is about solving problems, not about cramming as many patterns as possible in your codebase.
As for the ‘do patterns exist in functional programming?’-debate: Yes, they do! (To be exact, structural patterns do). Some common ones include recursion, map/reduce, higher-order functions and even the illustrious monads. However, these patterns have a much lower impact on how everything around them is designed than many of the OOP-patterns are, and all of these patterns more-or-less arise naturally (i.e. even when you do not know about them, you might already have ‘reverse-engineered’ them).
The fact that many people do not recognize these as patterns might indeed mean that it is so natural to use them in your language, that indeed they can be considered language features.
As for OTP: Message-passing is a complex thing. OTP packages this in the best way Erlang could. I completely agree that this does not feel like the most idiomatic way in all circumstances.
There do exist Elixir libraries that wrap GenServer & friends using macros to make it easier to use, such as ExActor. This works fine for 95% of the cases. For the other cases (more logic in the outward-facing function before calling handle_*, or needing to keep the dependencies of your library as small as possible) simple OTP is fine.
I would say that behaviours are something completely different from structural patterns: Behaviours make different parts of your code agree in what way something can communicate. This in no way restricts what else is going on in those parts of your code.
Finally though, recognizing patterns is actually important. This amazing TED-talk explains why better than I could
:
KallDrexx
Thank god someone said it.
Patterns being a bad thing is something that seems to be perpetuated by people who got burned because they took the idea of design patterns and “best practices” to mean “use all the time”, and then get mad when their square peg doesn’t fit in their circular hole, and they had to do frankenstein work to make it fit.
Formal design patterns are just a way to communicate different architectural approaches to solving a specific problem, not even to architect a whole application.
davearonson
![]()
Popular in Discussions
Other popular 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
- #javascript
- #code-sync
- #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
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








