However, I started a toy project in it and immediately ran into trouble due to its dynamic nature. Printing function arguments to see what they are, runtime errors... Is there a way to get around this besides adding spec tags on everything?
However, I started a toy project in it and immediately ran into trouble due to its dynamic nature. Printing function arguments to see what they are, runtime errors... Is there a way to get around this besides adding spec tags on everything?
If you want full static type checking, there is https://gleam.run/ which is a new language, and there’s also something that seems like a full static type checker for Erlang which is going to be released by Facebook soon (they use it internally). See this: https://elixirforum.com/t/facebook-is-writing-a-new-statical....
I, for one, am hoping that the Facebook solution allows us to implement something in Elixir to interface with it so that we can take advantage of it in Elixir, but that is yet to be seen.
That said, I'll take a look at Gleam. Thank you
Another trick I'll do, is to use (abuse) pattern matching:
def foo(%SomeStruct{} = arg, value) when is_integer(value) ...
That also helps Dialyzer narrow down possibilities too and will blow up on runtime.If you use VSCode, the ElixirLS module will auto-suggest @spec's for your functions.
From talking to the WhatsApp Erlang team a little it seems unlikely unlikely that the Erlang type checker will be usable with Elixir I'm afraid.
things are moving in that space, at least for Erlang
https://codesync.global/uploads/media/activity_slides/0001/0...