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?
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.
Ok yeah great point about the limits of async.
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.