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

dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
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
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
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
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
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
hpopp
To simplify some tasks at work, I wrote and published this package yesterday. It’s a simple macro that enables Access behaviour on struct...
New
Codball
Mix format works fine if run from the cmd. I’ve followed this to facilitate the implementation into VSC which involves downloading an ext...
New

Other popular topics Top

dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
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
sergio
I couldn’t find any guides that worked well with Phoenix 1.6.0 and esbuild. I hope this helps people test the waters and eases you into t...
New
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
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
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
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 42633 214
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
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
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

We're in Beta

About us Mission Statement