Hello again, I’m still in the process of learning Elixir. Almost done with Dave Thomas’ “Elixir for Programmers” course and I’m really enjoying it so far. But the course is a few years old and things seem to have changed a bit since. I’ve been following it using Elixir 1.17 and Phoenix 1.7.21 and I’ve had to tweak several things that don’t seem to be done the same way anymore, but the docs and even the help of Claude for specific questions have made the process very smooth. Having not really done a project by myself, let alone one that’s running on a production environment, I feel I’m still new to Elixir (my next step is to learn Phoenix more in-depth and try to develop an app on my own that will be reachable to the “outside world”) so I hope this isn’t a stupid question… But I absolutely love algebraic data types for modeling lots of domains and ran into this article:
Now I see the article is 3 years old and I’m also not sure how common this terminology and pattern are as far as idiomatic Elixir goes… My experience with Dialyzer is that if I add no flags, it’s a bit too permissive (it let me get away with writing multiple specs for the same function name with the same arity, which I was later told is a no-no), so I also tried to add various combinations of these flags:
"-Wunmatched_returns"
:error_handling
:underspecs
:overspecs
:specdiffs
:overlapping_contract
And ran into various issues with stuff that to me looked like it should’ve been correct but according to dialyzer the success typing was something way more specific that sometimes I tried to bend over backwards to accommodate, but it just wasn’t practical in some cases. I also had a bit of an issue with structs that had default values (e.g. if I set a field age
to have default value 25 and in my spec I tried to tell it was an integer(), when I used dialyzer with the flag :specdiffs it would give me an error that the type wasn’t integer() but was 25
instead). So in the end I opted to just exercise caution and discernment and kept dialyzer as it is by default, without any of those extra flags…
I also know that Elixir 1.18 already includes the gradual set theoretic type system. So I guess I’m wondering what the state of the art might be when it comes to algebraic data types, exhaustive pattern-matching, etc, or if they’re even idiomatic to Elixir or desired/necessary at all. I can see the case for it not being necessary since you can have your functions match the inputs you’re expecting and anything other than that will just not match and give an error and it’ll be no big deal because it’s not like it’ll crash your entire VM as it could happen with other languages…
But in case they are considered good practices of sort, I’d love to read more resources on how to make things work more smoothly… perhaps the state of the art when it comes to balancing version >=1.18’s type system with dialyzer?
…or I’d love to just hear what experienced Elixir devs’ thoughts are on the matter