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

Where Next?

Popular in Questions Top

chokchit
** (DBConnection.ConnectionError) connection not available and request was dropped from queue after 2733ms. You can configure how long re...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> somethi...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call t...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New

Other popular topics Top

TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 41539 114
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 47930 226
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

We're in Beta

About us Mission Statement