What does HackerNews think of dialyxir?
Mix tasks to simplify use of Dialyzer in Elixir projects.
1. Static Typing is planned and currently the top priority of the team
https://elixir-lang.org/blog/2022/10/05/my-future-with-elixi...
2. There is a type checking tool
https://github.com/jeremyjh/dialyxir
3. You can go a long way with pattern matching and guides in the meantime and have alot more guarantees that a typical dynamic typed language.
I use both dialyxir and Credo in my projects
As someone who has been writing Elixir professionally for 4-ish years, and who is otherwise about as big of a proponent of static types as is possible, this is simultaneously my biggest critique of Elixir, and also a critique that has ended up being more theoretical than not. I wish that it were statically typed, but in practice that hasn't been slowing me down.
Part of the reason for that is that while Elixir is dynamically typed, I've found that it's possible to pretend it is a statically typed language if you squint just right. By that, I mean making judicious use of typespecs [0], dialyzer [1], Norm [2], and just generally constraining the way you write code to mirror the sorts of code that you'd write in a language that offers algebraic data-types, like Haskell. I've been meaning to put together a blog post on what I mean by this, because I often hear people talking about how unusable Dialyzer is, so I feel like my team is a rare example of a large production app that requires that Dialyzer typechecks on every build. This makes large-scale refactoring of our app almost (but not quite) as easy as it would be in Haskell.
The macro system in Elixir also means that it's possible to write libraries like typeclass [3], that offer compile-time guarantees (using compile-time property tests!) that your implementations correctly implement a given interface. I think that as the language evolves, we'll be seeing a lot more examples of macros that move runtime logic into the compilation step, to offer compile-time guarantees and safety. For example, a few weeks ago, I prototyped an experimental library in a few hours that added support for compile-time OCaml style parameterized-modules. [4]
Obviously, all of these techniques don't get you quite as far as proper static typing would (though the Whatsapp team is working on static types for Erlang! [5]), but the rest of the language and the ecosystem is just so well thought out, that I've been okay with that!
[0] https://hexdocs.pm/elixir/typespecs.html
[1] https://github.com/jeremyjh/dialyxir
[2] https://github.com/keathley/norm/
[3] https://github.com/witchcrafters/type_class
The Norm library (https://github.com/keathley/norm) is an attempt at higher-level, more expressive type checking which I think shows a lot of promise, but I've not adopted it in a real project yet.
[0] https://github.com/asummers/erlex [1] https://github.com/jeremyjh/dialyxir
I'm working on making the dialyzer error messages better, too, in Dialyxir[0] and Erlex[1] =).
[0] https://github.com/jeremyjh/dialyxir [1] https://github.com/asummers/erlex
The tl;dr for that project is that it runs dialyzer, finds the relevant Warning module for each warning, which will pretty print parts of the error output into a larger explanation, which involves taking the output, lexing it, parsing it, then pretty printing the IR back into Elixir, then running through the formatter.
It should maybe come bundled with mix, as some other tools, that way it'll be more approachable.
Also there's a wrapper for it, which helps in the process.[0]
Have you guys looked into Dialyzer?
Dialyzer is a static analysis tool for Erlang and other languages that compile to BEAM bytecode for the Erlang VM. It can analyze the BEAM files and provide warnings about problems in your code including type mismatches and other issues that are commonly detected by static language compilers. The analysis can be improved by inclusion of type hints (called specs) but it can be useful even without those. For more information I highly recommend the Success Typings paper that describes the theory behind the tool.
That's from the Dialyxir (for using Dialyzer w/Elixir) github page: https://github.com/jeremyjh/dialyxir
More: http://learnyousomeerlang.com/dialyzer
(Perhaps this should be read first: http://learnyousomeerlang.com/types-or-lack-thereof )
And this is the Success Types paper behind it (mentioned in the excerpt above):
https://www.it.uu.se/research/group/hipe/papers/succ_types.p...