mmyers

mmyers

Why are Application.{fetch,get,compile}_env functions not consistent?

In the Application module, I know compile_env is newer than get_env and fetch_env, but it seems like it would be helpful to have the same function signature that allows passing a “key_or_path” to all of these.

compile_env(app, key_or_path, default \\ nil)
get_env(app, key, default \\ nil)
fetch_env(app, key)

I’d like the ability to do this:
path = Application.fetch_env!(:device, [:connection, :polling_interval])
and have the run time checks related to compile_env catch it.

Here is why I’m thinking of this.
Note: I realize this is contrived, and you’d almost have to try to do it wrong to have this code. but still, why shouldn’t we make the functions have the same signature?

When I have a config, sometimes I want to make parts of it set at compile time, and other parts of the config dynamic (set at run time).

And without matching calls, it seems like you could hide the problem compile_env is trying to fix.
For example:

If you have this in one place:
@polling_interval Application.compile_env!(:backend, [:connection, :polling_interval])

Nothing prevents you from doing this in another place:

# In a config file like config/releases.exs 
custom_polling_interval = System.get_env("POLLING_INTERVAL")

config :backend, :connection,
  polling_interval: custom_polling_interval,

And then trying to do this (and getting a different value than the result from compile_env), which is what compile_env tries to help us avoid.

connection = Application.get_env(:device, :connection)
path = Keyword.fetch(connection, :polling_interval)

Maybe that will still get a runtime error, and my example is invalid. :man_shrugging:

Most Liked

LostKobrakai

LostKobrakai

I can’t find the source anymore, but iirc it’s plain backwards compatibility. Application.get_env(:myapp, [:abc, :def]) means it’s looking for the key [:abc, :def], not the value at the path [:abc, :def].

Where Next?

Popular in Discussions Top

sashaafm
I’m trying to evaluate the best combo/stack for a BEAM Web app. Right now I’m exploring Yaws a bit, after having dealt with Phoenix for a...
New
owaisqayum
I have a sample string sentence = "Hello, world ... 123 *** ^%&*())^% %%:>" From this string, I want to only keep the integers, ...
New
arpan
Hello everyone :wave: Today I am very excited to announce a project that I have been working on for almost 3 months now. The project is...
New
AstonJ
If a newbie asked you about Phoenix Contexts, how would you explain the basics to them? Feel free to be as concise or in-depth as you li...
New
mbenatti
Following https://github.com/tbrand/which_is_the_fastest |> https://raw.githubusercontent.com/tbrand/which_is_the_fastest/master/imgs...
New
CharlesO
Erlang :list.nth simple, but 1 - based nth(1, [H|_]) -> H; nth(N, [_|T]) when N > 1 -> nth(N - 1, T). Elixir Enum.at … coo...
New
restack_oslo
Hello, Please pardon me for any faux paux. I am 46 and this is my first time on a forum of any kind. I wanted to to get answers from tho...
New
AstonJ
If so I (and hopefully others!) might have some tips for you :slight_smile: But first, please say which area you’re finding most challen...
New
wmnnd
The Go vs Elixir thread got me thinking: Would it be too hard to implement a simple mechanism for creating Go-style static app binaries f...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New

Other popular topics Top

Nvim
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help. Where are they similar? Where do they differ the m...
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
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 126479 1222
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 53690 245
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

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement