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

nobody
How to bind a phoenix app to a specific ip address? could not find anything about that, nowhere, unfortunately, but for me this is quite...
New
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
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
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
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
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
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

Other popular topics Top

malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 41989 114
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39467 209
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
AstonJ
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition) It’s been a while since we first asked this, I...
208 31265 143
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52673 488
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

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement