ctrlshiftbryan

ctrlshiftbryan

Design: OTP App. vs Modules of pure functions

I’ve been doing Elixir and Phoenix for about a month and have not yet seen a need to a build an OTP application yet. But am I missing something?

My newb brain is just trying to over simplify it and say that unless I need to maintain some type of state I don’t need an OTP application.

Maybe a use case would be needing to do things asynchronously but I can just use the async feature with my pure functions for that.

For example why is ‘devinus/poison’ an OTP application and not just a set of modules with pure functions?

There is this big part of my that feels like using OTP isn’t that different than OO and it brings back all that unneeded complexity of mutable state. So I only want to use it is I absolutely have to.

What questions should I be asking to decide if something should be turned into an OTP application?

Most Liked

sasajuric

sasajuric

Author of Elixir In Action

The word application is a bit of misnomer. Component would be a better term. Each library should be an OTP app, since that allows proper specification of runtime dependencies (with applications in your mix.exs). That in turn allows various tasks to work on the project. For example, exrm will include all dependent applications in the OTP release. Another example is dialyze which builds PLTs from runtime dependencies.

It’s worth noting that poison is a simple OTP app that doesn’t start any process. Such applications are called library applications.

Finally, it’s worth mentioning that any project you build will mix will generate an OTP app.

terakilobyte

terakilobyte

This is a question that interests me too. I have a vague notion in my mind. So far, this is what I’ve gathered and would like it cleared up.

Reach for OTP when some operation I might be performing could potentially take a long time. It might depend on outside resources out of my control, or be computationally expensive. Additionally, if I care about the result of that operation, OTP will allow me to retrieve the result in a safe way. If I call await too soon, I’m stuck waiting for the result.

If I need some form of state storage that doesn’t need to persist a long time, go for OTP. An agent or genserver is cheap to start up.

ctrlshiftbryan

ctrlshiftbryan

Ok yeah great point about the limits of async.

Where Next?

Popular in Questions Top

aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
Phillipp
Hey, I have a NanoPi-M3 and try to install Elixir on their Ubuntu image. I followed the Raspberry Pi installation instructions from the ...
New
makeitrein
Hey all, just started picking up Elixir last week and am writing a scraper as a learning project. Baby step #1 is extracting the number ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
idi527
I’ve been re-reading swift book again and noticed that multiline strings there don’t have a trailing line break, unlike in elixir iex(2)...
New

Other popular topics Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

We're in Beta

About us Mission Statement