stratacast

stratacast

Packaging for multiple Elixir versions

I have a package published with Hex, and when I wrote it, 1.10.3 was the current release of Elixir. I know that 1.11 added some stuff, and I don’t think it impacts my code (I still need to verify this), but it made me wonder, how are we supposed to be supporting Elixir versions? I’m guessing I’d have to do some branching of my code to have a 1.10.x version and a 1.11.x version if I ever wanted to add additional features in newer releases? Then is there something within the mix tools that lets me publish multiple copies or something? I poked around the web for answers but I’m not certain what the best method is

Marked As Solved

wojtekmach

wojtekmach

Hex Core Team

Then is there something within the mix tools that lets me publish multiple copies or something?

Nope.

I’m guessing I’d have to do some branching of my code to have a 1.10.x version and a 1.11.x version if I ever wanted to add additional features in newer releases?

Yup!

The most common option is to check if a given function (that is only available in the most recent release) is defined. Let’s say you want to use Enum.product/1 that will be released in Elixir v1.12.

I’d do something like this: (along with a TODO as a reminder)

def f(x) do
  enum_product(x) / length(x)
end

# TODO: remove when we depend on Elixir v1.12
if Code.ensure_loaded?(Enum) and function_exported?(Enum, :product, 1) do
  defp enum_product(x), do: Enum.product(x)
else
  defp enum_product(x), do: # custom implementation
end

Stuff like this adds code complexity and maintenance burden so it’s usually a good idea to have pretty aggressive minimum Elixir version requirement. I’d consult Compatibility and deprecations — Elixir v1.20.2 and see which version still receives bug fixes and target around that. After all, your users should be on recent Elixir versions to receive those bug fixes.

Where Next?

Popular in Questions Top

lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call t...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
dotdotdotPaul
Okay, I’m having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I’m sure I’...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
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

Other popular topics Top

danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 29377 241
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 41539 114
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 43622 214
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New

We're in Beta

About us Mission Statement