1 hour ago · 5 min read1000 words · Culture · hide · 0 comments

My Elixir library pet peeve: application.ex. There are very few reasons for why you would ever need to have a library be its own application, and making it one often encourages anti-pattern library design that leads to less usable code. And yet, I still see a lot of Elixir libraries do this. What does application.ex do This is the file that includes the start callback for your application. For most of us, this is how we’re used to working with Elixir. We create our application with mix phx.new or mix new --sup and that’s what pops out. You get a nice little supervision tree and use it to add your GenServers and whatnot, maybe you put in a logger handler in the startup logic, some logs, maybe set up some telemetry. It’s a very intuitive place to put start up logic. In fact, tons of your dependencies do this. Try it out for yourself. Here’s what I get when I list the running applications that have their own start callback, for this blog, locally. iex(1)> :application.info()[:running] |>…

No comments yet. Log in to reply on the Fediverse. Comments will appear here.