GusGA

GusGA

Difference between in load a large array string from a config file and load from a module

I forked an elixir lib that generates heroku random names.

On the “master” repo, the nouns and the adjectives are loaded from a config file. I change it, I create a module from each one, one for the nouns and one for the adjectives.

Now, Which is the benefit or difference from load it from a config file or a module?

Thanks in advance.

Most Liked

idi527

idi527

:waving_hand:

Load from config = lookup in an ets table. To compare ets lookup with a module lookup, we’d need to know how exactly the latter happens. I’ve seen some people putting data in maps and then just calling Map.get on it like

defmodule SomeModule do
  @data %{
    a: 1,
    b: 2
  }

  def lookup(key) do
    Map.get(@data, key)
  end
end

which would mean that the difference is the same as ets vs maps.

The other way I’ve seen people use is utilizing constant pools:

defmodule SomeModule do
  data = %{
    a: 1,
    b: 2
  }

  for {k, v} <- data do
    def lookup(unquote(k)), do: unquote(v)
  end

  def lookup(_not_found), do: nil
end

You can learn more about it from the discordapp/fastglobal readme. It’s always been faster in my experience than the map approach above. This was also the approach I used (without any dependencies though) when I needed something like heroku random name generator as well, mostly because it was more readable than the other approaches I could think about.

Last Post!

GusGA

GusGA

Thank you for taking the time to explain.

Where Next?

Popular in Questions Top

Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
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
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

Other popular topics Top

KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36820 110
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
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" =&gt; #BSON.ObjectId&lt;58eb1a7a9ad169198c3dXXXX&gt;, "email" =&gt; ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 49266 226
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

We're in Beta

About us Mission Statement