Behaviours, defoverridable and implementations

I believe you reached the conclusion the use of @impl true is not worth for you (which is fine). :slight_smile:

Misuse and overuse is going to happen pretty much with any feature. For example, the exact same could have been argued about the Registry.

Some extra comments:

I am not sure I follow. The point is exactly to associate the usage of the behaviour with its implementation. The only way to keep it together would be with something like:

impl MyBehaviour do
  def bar, do: :ok
  ...
end

but I believe the above looks… too foreign?

This should be fine because you cannot have duplicated callbacks. Plus the majority of times you are implementing only a single behaviour, so @impl true is less noisy than repeating @impl Foo.Bar.Baz multiple times. For cases you are using multiple behaviours, you can do @impl Foo.Bar.Baz and @impl A.B.C.

Unfortunately we cannot make it required because that would emit too many warnings. However, we can guarantee that, if you have used @impl true once in a module, you have to use it for all callback implementations.

As mentioned in the proposal, it also gives valuable feedback to anyone who is reading the code, especially if the purpose of some particular function is unclear. We can all identify handle_call/3 but how many Phoenix developers would know that an action/3 in a controller is a Phoenix.Controller callback?

Thanks for the feedback!

1 Like