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.16.0 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

vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
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
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
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
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
Fl4m3Ph03n1x
Background Let’s assume I have a typical GenServer that receives messages as requests, does some operation in a DB and returns responses....
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
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
jc00ke
Expanding on this topic: https://forum.elixirforum.net/t/map-typespec-question/19217 Let’s say I have a map with required and optional k...
New

Other popular topics Top

chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30048 115
New
peerreynders
Manning 2016 Halloween weekend sale via Deal of the Day Friday, October 28 - Half off all MEAPs - code WM102816LT Saturday, October 29 ...
326 29600 154
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
977 41022 311
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
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
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
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
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