3 ms·
Look at Dialyzer and http://elixir-lang.org/getting-started/typespecs-and-behaviours.html#types-and-specs http://elixir-lang.org/getting-started/typespecs-and-b
by im_down_w_otp 10y ago
Look at Dialyzer and http://elixir-lang.org/getting-started/typespecs-and-behaviours.html#types-and-specs http://elixir-lang.org/getting-started/typespecs-and-behavio...
Also, Elixir community... there seems to be a paucity of awareness of Dialyzer and Typespecs. Perhaps they could be more prominent? They're included in the reference docs, but not really so much in a way that indicates what they are or how one would use them when writing their own software in Elixir.
There are many, many classes of problems that can be discovered before they're discovered at runtime. It's made a little harder in Elixir-land due to limited Map support in Dialyzer and Map usage being extremely common in Elixir code, but still spec'ing your functions is a good practice and habit to get into anyway.
- knewter 10y agoThe latest Erlang release fixed the Map problem with Dialyzer. It was entirely the reason I was lax with specs. I'd love to get a workflow more like this one: https://medium.com/@barruumrex/seeking-simple-satisfaction-2a098902ddff https://medium.com/@barruumrex/seeking-simple-satisfaction-2...
- im_down_w_otp 10y agoFor the uninitiated... Erlang 19's included Dialyzer improves the scenario of type-checking maps in useful ways. Namely that now you can represent an empty map, an arbitrary map of any type, and a partially arbitrary map which must include certain key type and value type associations but is not limited to those. Which leaves out one representation which is a map which includes and only includes a specific set of key type and value type associations. Erlang 18's Dialyzer has basically just #{} =:= map() which is equivalent to the union of #{none() => none()} and #{any() => any()}, so it was basically a giant escape hatch in the type-checking system, and thus not particularly valuable. Looking forward to a pending change in laxness as a result of the coming changes in 19. :-)