|
|
|
|
|
by davidclark
323 days ago
|
|
Well written typespecs + dialyzer catches most things you’d want to catch with a type system: https://hexdocs.pm/elixir/typespecs.html There is also pattern matching and guard clauses so you can write something like: def add(a, b) when is_integer(a) and is_integer(b), do: a + b def add(_, _), do: :error It’s up to personal preference and the exact context if you want a fall through case like this. Could also have it raise an error if that is preferred. Not including the fallback case will cause an error if the conditions aren’t met for values passed to the function. |
|
It reminds of the not-missed phpspec, in a worst way because at least with PHP the IDE was mostly writing it itself and you didn't need to add the function name to them (easily missed when copy/pasting).