I've got some Elixir code on which I was working with some colleagues. The very simplified code below should demonstrate the essence of the question I'm trying to resolve.
defmodule DemonstrateQuestion do
def fh(), do: :unknown
def fh("A"), do: :a
def fh("B"), do: :b
def fh(_), do: :unknown
end
defmodule AlternateBehavior do
def fh(_\\nil)
def fh("A"), do: :a
def fh("B"), do: :b
def fh(_), do: :unknown
end
I prefer the approach in DemonstrateQuestion because it explicitly calls out the zero arity function head. But I cannot detect any functional difference between DemonstrateQuestion and AlternateBehavior. So my question is, is there a valid technical reason (e. g. calling out the zero arity function head helps Elixir to generate better byte code) to prefer one approach or the other?