Fl4m3Ph03n1x

Fl4m3Ph03n1x

Gradualyzer vs Dialyzer - main differences?

Background

In a post I made about having static types in Elixir, someone mentioned the tool Gradualizer. This came as a surprise to me, as though I have seen and read quite a lot about Dialyzer, I have never seen an Elixir book mention Gradualizer.

Questions

I understand Gradualizer aims to provide static typing for erlang (and I suppose Elixir) via gradual typing, while Dialyzer takes a different approach.

But as someone who doesn’t understand the differences to both systems, this is new terrain.

  1. What is the main purpose of Gradualizer in regards to its ancestor? (to replace Dialyzer, be a competitor, improve upon it…)
  2. What are the main differences between one tool and the other?
  3. Why should I move to Gradualizer when Dialyzer has been the de facto tool for typing in erlang/elixir since… well, forever?
  4. Is Gradualizer ready for usage in real projects? (I understand it isn’t, please correct me if I am mistaken)

Marked As Solved

Also Liked

erszcz

erszcz

Thanks for the feedback! We’re trying to make Gradient as user-friendly as possible - there is significant effort put into making sure it integrates nicely with Elixir, but indeed, the software is still experimental.

Could you create a ticket with an error that you consider hard to read? Or given an example here? I’ll be happy to take it forward.

That’s the never ending story of type checkers / static analysis - how to make the checker detect real problems in code on one hand, yet still be flexible enough to allow for all quirks of the language and full expressiveness on the other. However, even more so in this case, we would be extremely happy if you could report false positives on the project’s GitHub page.

Any feedback is good feedback, so keep it coming :+1: I strongly believe it might only lead to making the tool better!


Getting back to main differences.

Gradualizer has a different approach than Dialyzer in reporting errors. Dialyzer advertises that “it’s never wrong”, which is true, but sometimes its feedback is a bit hard to use (the lovely “function … has no local return” and no direct hint on what to do with it). It’s also quite slow, though it’s not as much of a problem as it used to be a few years ago.

Gradualizer reports more kinds of errors and allows for some tricks known from other statically typed functional programming languages like exhaustiveness checking - see example screenshots of Gradualizer being used with the Erlang Language Server in this post. It’s also significantly faster, as it doesn’t require generating PLTs. Actually, thanks to its speed it’s very convenient as a background tool in the editor. However, in this experimental phase, it means some false positives might get reported.

To get a better feel of what’s possible with Gradualizer, that’s not possible with Dialyzer, you might want to watch my lightning talk about typechecking Elixir from ElixirConf EU 2021 or read about the typestate pattern in Erlang.

In the long run Gradient should offer everything Gradualizer does and maybe even a bit more thanks to some macro magic :magic_wand::sparkles:

LostKobrakai

LostKobrakai

Dialyzer was build on the idea of success typing. This makes so that dialyzer can work even without user input, just based on code itself. It also tries to not report false positives quite heavily. But it comes with the downside of not detecting many of the error cases other static typing systems can detect. (The link below even argues that dialyzer is not a type system)

Gradualizer is a completely different approach. Afaik it doesn’t do type inference, so unless you manually provide typespecs it does nothing. But for the places you do provide them, it’ll statically check for errors even beyond what dialyzer would be able to detect or would acknowledge. The other big part between the lines is that you can gradually add type safety to your systems. It’ll work with as much typespecs as the code does provide.

For more details see this one:
https://github.com/josefs/Gradualizer/blob/master/talks/talk.md#comparison-with-dialyzer

Essentially both tools try to detect errors, but do that in quite different ways with therefore quite different tradeoffs.

Rich_Morin

Rich_Morin

The most recent commit to Gradualixir was almost two years ago. Can someone give me an idea of its current status and prospects? Is anyone using it as a production tool?

-r

Last Post!

dimitarvp

dimitarvp

I don’t disagree but I think people fear this more than they should. I’ve worked for financiers a few times and yeah, there you should be afraid of lag spikes going to 10 milliseconds; something most apps wouldn’t even notice.

Everywhere else I ever worked though? Meh. Nobody bats an eye if 1 out of 20 requests takes 3 seconds even. Nobody cares. And to this day Rails developers insist that ActiveRecord (the ORM of Rails) being responsible for 100-150ms delay per web request (admittedly only if it has 3-10 DB queries, of course) is small and is not important. In the meantime a similar Phoenix endpoint in its entirety returns in 7ms at the most.

When it comes to such an impressively fast dynamic language environment like the BEAM VM I don’t view some minuscule delay like 2-10 more ms as consequential. Anything that helps avoid bugs, not leak people’s private data, and not lose money should be counted as a win, even if it comes at the expense of performance.

Another example: Rust’s compiler is slow but it does eliminate several entire classes of bugs by the mere virtue of your program compiling.

IMO we need more such tech in our line of work, including in the Elixir ecosystem. It’s amazing how much traffic can a mere modern i3 mini-computer with 32GB RAM and a SATA III SSD can serve; we should focus on correctness because buying 20% more hardware capacity is a rounding error in most companies.

Where Next?

Popular in Questions Top

RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

Other popular topics Top

stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New

We're in Beta

About us Mission Statement