Tano

Tano

Why Elixir is warning me about not implemented behavior functions?

Hello everyone,
I am new to Elixir, but I am quite confused. When I define @callback functions the module that is using the behavior is not producing error if that function is not implemented, it is just showing warning. I question would be what is the idea behind showing warning instead of throwing some error, thanks :slight_smile:

Most Liked

peerreynders

peerreynders

Just my guess - not an official explanation.

I think the warning makes sense in the context of Elixir (or Erlang) being dynamically typed. If Elixir (and Erlang) was statically typed then an error would make sense.

Dynamically typed languages lend themselves to REPL-Driven-Development, i.e. you can build and exercise code in the absence of other functionality (to be added later) as long as your current runtime execution path doesn’t run off into the “other non-existent” parts of the code. With a statically typed language this is impossible - you would at least have to “stub out” all the other parts of the code - even if you currently do not plan to execute them at runtime (during development).

Now granted unlike JavaScript, Elixir (and Erlang) still needs to successfully compile before anything can be run - but to use XML terminology - successful compilation simply means the code is “well formed” but it doesn’t mean the code is “valid”. The fact that Elixir (and Erlang) requires compilation should never be mistaken for it being “equivalent to” statically type checked

By only issuing a warning, you are free in development to write and run tests for parts of the behaviour that do not rely on that particular callback. This would be especially handy for behaviours with a relatively large number of callbacks. So the warning lets you get the first tests to run much more quickly - without necessarily having to sketch out the entire behaviour implementation first.

Now deploying code with these type of warnings (or ideally any warnings) into production would be questionable.

dimitarvp

dimitarvp

Well, contracts are worth nothing if they are not enforced. I actually find this compromise rather surprising. :107: :017:

wojtekmach

wojtekmach

Hex Core Team

I don’t know the rationale, however to turn warning into error yourself you can pass --warnings-as-errors to mix compile, mix test and many other tasks.

Where Next?

Popular in Questions Top

JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
Werner
Hi, I’m using Ubuntu 18.04 and after updating to OTP-24.0 yesterday i have this warning when I run “mix local.hex”: 14:57:30.512 [warn] ...
New
logicmason
Hi there, I'm working through my first release with elixir/phoenix. I've built a release with distillery and found that it crashes when I...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
Phillipp
Hey, I have a NanoPi-M3 and try to install Elixir on their Ubuntu image. I followed the Raspberry Pi installation instructions from the ...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
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
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New

Other popular topics Top

lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
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
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
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
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New

We're in Beta

About us Mission Statement