What is the best way to define Elixir App wide constants and errors?.In languages like go lang we export and import constants and errors.
What is the idiomatic or best, the De facto industry standard of Elixir community or generally design pattern for it?
requirements: we should be able to match them in guards and clauses, it should be as similar to normal variables in elixir function.What if we want to have constants for UI and backend at the same time, Like for an atom UI will show a String, in backend a integer.
ps: I found this article from 2016.
And some examples from timex lib, but cant use them in guard or clause
defmodule MyApp.UnixErrors do
defmacro __using__(_opts) do
quote do
@bad_argument :badarg
@invalid :einval
end
end
end
defmodule MyApp.UserModule1 do
use MyApp.UnixErrors
def hello(), do: @bad_argument
end
This too is some level of compile-time dependencies but they are flat, there are no cycles or deep graphs involved.
Ah, you mean the module attributes can’t start with a capital letter. Can’t help you there, but I don’t see why would that be a hard requirement for you either.