josevalim

josevalim

Creator of Elixir

PSA: Do not use private APIs, request a feature instead

Hi everyone,

With the v1.7 release, we have received reports of some dependencies no longer working properly on the new release.

Developers should not expect breaking changes from Elixir on minor and patch releases. We outline our compatibility and deprecations policy in our docs: Compatibility and deprecations — Elixir v1.19.5

This means that, if there is something effectively broken in a new release, it is one of:

  1. We messed up and accidentally introduced a regression, which we have to fix
  2. We fixed a bug that you were accidentally relying on. It is still our bad. We will either have to accept this or find a better way to do a bug fix (for example, introduce a new function and deprecate the old one)
  3. Some project (it could be yours) was using private API

Thanks to everyone, we are able to catch the huge majority of the occurrences of 1 and 2 during the RCs. However, there are still many cases where developers are simply using private Elixir modules and functionality - which may be renamed or completely removed in new Elixir versions. We do not provide any guarantees for private functionality. Needless to say, DO NOT USE PRIVATE APIs.

Using private APIs generate a negative cascade effect in the community because it makes developers unable to update to the latest Elixir version.

How to help

If you are a user of a project and you notice it depends on private functionality, consider reporting a bug or submitting a pull request.

If you are a library author and you are using private APIs, don’t. :slight_smile: If Elixir has a functionality that you need but it is private, please open up a feature request to make the desired functionality public.

Also, consider running your CI builds against Elixir master. It is as easy as:

- wget https://repo.hex.pm/builds/elixir/master.zip
- unzip -d elixir master.zip
- export PATH=$(pwd)/elixir/bin:${PATH}

Here is more info on available precompiled Elixir versions, branches and tags: GitHub - hexpm/bob: The Builder

While I wrote this thinking about Elixir, it likely applies to most libraries out there.

Most Liked

aseigo

aseigo

Fun idea. Made it my evening project. GitHub - aseigo/hexagon

Am running it on my laptop right now with Elixir 1.7.1 and Erlang 21.0.4 … let’s see what happens. If the community feels it would be actually useful, I could run it regularly on servers at work. Could also extend it with other checks, e.g. perhaps harness credo to do some static analysis.

It is pretty bare-bones … perhaps logging with json would be nicer for later usage. Also just noticed it fails for rebar projects, which should be easy enough to fix. So rough edges, to be expected for a few hours thrown at a project, I guess … improvements welcome :slight_smile:

It has already found packages with problems, e.g.:

 == 23:15:30.197
FAILED at compile: /home/aseigo/packages/ex_loader/0.4.1
errors: could not compile dependency :pre_commit_hook, "mix compile" failed. You can recompile this 
dependency with "mix deps.compile pre_commit_hook", update it with "mix deps.update pre_commit_hook" 
or clean it with "mix deps.clean pre_commit_hook"

Neat.

edit: bonus round … Since I had them on disk already, I ran cloc over the entire set of packages. https://exote.ch/~aseigo/state_of_hex.txt

bbense

bbense

It might be nice to give people a reminder about the @moduledoc false convention. Or even better a tool that flags uses of private apis from the standard lib as a compile time warning.

kelvinst

kelvinst

Also, it would really be nice to have at least a warning when a private API is being used by a module outside its application. I remember that being discussed somewhere else but don’t remember the outcome of it, maybe that’s not even possible, IDK.

CptnKirk

CptnKirk

Wouldn’t it be better to be able to have truly private APIs built into the language so that compilation against “private” modules and functions would fail? Seems like something the language owners could add.

Something like a defpmodule macro that accepted either as part of the module def or possibly a well known constant, a list of module friends able to access internally public functions.

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

I think this is a good example of why the pragmatic version of “Don’t use private APIs” is “Be aware of the risks of using private APIs”. Any feature that provides some kind of compile time check on private API usage should have an escape hatch, because there are situations where being locked to a specific version of the language and having a feature is sensibly considered a worthwhile trade off.

A tracking mechanism for private usage would actually make that sort of thing safer, since it’d be easier to audit.

Where Next?

Popular in Notices Top

josevalim
Hello everyone, We had a discussion on elixir-lang-core about deprecating the use of ‘single quotes’ in Elixir for charlists. The use o...
New
josevalim
Hello everyone, Last year we have announced GenStage and then developed Flow. Our initial plan was to make GenStage part of Elixir. Tha...
New
josevalim
Hi everyone, With the v1.7 release, we have received reports of some dependencies no longer working properly on the new release. Develo...
New
ericmj
We are moving the builds for precompiled versions of Elixir, Erlang/OTP, and Hex itself. These are currently hosted on https://repo.hex.p...
New
josevalim
One common concern about using Elixir libraries is that use SomeModule does not make clear how it impacts the caller. While the goal of u...
New
josevalim
Hi everyone, I have updated Elixir’s wiki page on IDE/Editor support and I am now linking to it from the website. If you know of other ...
New
josevalim
Hi everyone, Elixir v1.19.0-rc.0 included a deprecation of the struct update syntax. However, we will ship with a different warning on E...
New

Other popular topics 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
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
AstonJ
You’re a programmer, so you don’t need spoon feeding with the conventional drivel about “this is an integer.” No. You need to know what’s...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
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
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
magnetic
Hey :wave:t3: Elixir community, I’ve been learning Elixir, and working on some side projects. My editor of choice is VSCode, and althoug...
New

We're in Beta

About us Mission Statement