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

senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
vac
Hi, I’m quite new in Elixir and I’m trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and I...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> somethi...
New
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
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New

Other popular topics Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
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
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39297 209
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
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

We're in Beta

About us Mission Statement