Evaluate: should start_link be excluded from behaviour callbacks? #3
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Question
When defining a behaviour for a module that wraps a GenServer, should
start_link/1be included as a@callback?Argument against including it
start_linkis called by the supervisor, which is configured with the concrete module directly ({QuoteFeed, opts}or{QuoteFeed.Fake, opts}). Nobody callsstart_linkpolymorphically through the behaviour interface.Behaviours exist to define the interface that callers use — the functions that application code dispatches through.
subscribe/2andunsubscribe/2are genuine polymorphic interfaces.start_linkis lifecycle boilerplate.Including it adds noise to the contract without enabling any real polymorphism that the supervision tree doesn't already handle.
Argument for including it
child_spec/1wrappers) might want to callstart_linkthrough a module variableIf we decide yes (exclude start_link)
patterns/behaviours.mdwith guidanceContext
Came up during PR #662 (QuoteFeed @behaviour). The PR currently includes
start_linkas a callback. If this becomes a best practice, we'd remove it and update the pattern.Evaluation approach
Search popular/robust Elixir applications and identify what they do:
start_linkappear in their callbacks?Ecto.Adapter). Does it include lifecycle functions?Look at what the ecosystem has settled on through practice, not just theory. If mature libraries consistently exclude
start_linkfrom their behaviour definitions, that's strong evidence for the convention.