mguimas

mguimas

Do you use `defoverridable` (and `super`) in your code?

Hello,

What are you using defoverridable and super for?

I have searched for uses of these features, in large projects like Ecto, Ecto_SQL and Hex.pm, and only Ecto_SQL makes use of defoverridable, but only at one place. In addition, there is no trace of super being used in these projects.

Are these features not of much use in FP (Functional Programming), or at least, in FP as implemented in Elixir / Erlang?

What do you think?

Thanks

Most Liked

david_ex

david_ex

The only places I’ve personally seen them used is when macros define default function implementations that could be overridden. For example, GenServer defines default implementation of handle_info etc. (see https://github.com/elixir-lang/elixir/blob/v1.8.1/lib/elixir/lib/gen_server.ex#L802), but the using module can of course define its own version that would override it. I image super is used mainly in those same cases.

hauleth

hauleth

Very rarely. IIRC the only situation where I have used defoverridable so far is Opencensus.Plug library where user can define function for creating span name if they need to. It could be solved by injecting mfa(), but I think this solution is a little bit clearer and simpler.

mguimas

mguimas

So, in your own code you have not used them, but you see they being used to provide default implementations for behaviour callbacks, like the one you linked.

I wonder if that could not be also solved using dependency injection of the callback implementation to use :thinking:

Where Next?

Popular in Questions Top

Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
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
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
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
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
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

Other popular topics Top

lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30048 115
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
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
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
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
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New

We're in Beta

About us Mission Statement