jakespracher

jakespracher

I am working on a few new elixir projects and am finding I want to encode more type information than vanilla elixir syntax allows as I understand it. For example, the return values of functions.

I could adopt dialyzer and the @spec convention, but

  1. Chris McCord himself has said it’s not worth it (Do you use Dialyzer in your projects? - #18 by chrismccord)
  2. The docs say this convention will be phased out (Gradual set-theoretic types — Elixir v1.17.3)

So, what is the best thing to do right now if I want to encode type information in Elixir? Or should I just not?

Showing Posts 1 to 10

sodapopcan

sodapopcan

That’s just Chris’ personal opinion. I would use @spec for now as it will be a while before $ is ready. Years, possibly.

10
Post #1
sbuttgereit

sbuttgereit

I’m not going to lie… in those projects where they’re missing I find it frustrating sometimes. Not because there’s huge missed value in Dialyzer… I think Chris’s view on that is absolutely reasonable and while I’ve ended up on the other side of that thinking, I can’t blame him for his position. No what drives me crazy about the missing typespecs is the lost documentation value. I often times will look at the documented typespecs, as the client developer using a library, to understand if… at the very least… I’m understanding the intention of a given API correctly. Even in my own code, they’re great to remind me of what I was thinking particularly if I haven’t touched that part of the application in awhile.

Assuming the existing typespecs get phased out in favor of some other approach, it’s still going to be awhile and the set-theoretic types (and its notation) may be likelihood at this point, but I haven’t heard anyone say its a certainty yet. Also, that transition would have a pretty long window, I imagine, just thinking of the consequences of such a deprecation.

So I continue to write typespecs and will do so until the actual replacement is released.

10
Post #2
sodapopcan

sodapopcan

Right, there’s even a chance $ may even never happen! I’m still assuming it will, but it’s not a guarantee.

FWIW share Chris’ opinion, though I’ve been coming around to types, especially as they are planned for Elixir.

D4no0

D4no0

There is a very good chance the set-theoretic types will not make it very soon IMO, the complexity and intricacies involved in solving that problem is night and day compared to plain types we have in static languages, not to mention that even those are extremely hard to get right.

I personally tend to use typespecs on new projects, but they are more like mentioned by @sbuttgereit, for documentation purposes, even though in 95% of cases I always read documentation from source code :joy: . I found they sometimes can catch some nasty bugs that you never anticipated, however that is very rare and it’s more related to you passing around random data structures.

sodapopcan

sodapopcan

Yes, I definitely appreciate them for documentation purposes in libraries, I should have said that, but I’m working and keep getting distracted by Elixir Forum :upside_down_face:

But ya, that’s been my experience, at least writing CRUD web apps :smiley: As a pro-dynamic language person, I’m always cognizant of types and find it pushes me to write code in a way where the args and return types are obvious more-or-less from a glance. Of course it’s not as clear as a spec (especially the return type). I always get annoyed during type discussions when people seem to think people are into dynamic languages so “they don’t have to think about types.” I always thought, “Other than juniors those people don’t actually exist…” but of course, we only know our own experiences and the codebase I most recently inherited was written by experienced people where functions return random types so… d’oh, ok I understand now. I’m certainly not against added safety, though, which is why I’m excited about Elixir’s proposed implementation using existing constructs with a cleaner spec syntax.

But yes, I believe José has said it’s good five years out before the type system is “done.”

D4no0

D4no0

I recently worked in a huge elixir project that is one big web app. There is a huge amount of devs (there are about 400 MRs per day) working at the same time on that app, so the rules are pretty constrained on what can you do there.

The reality I saw is that in some cases you have to break the rules to make the code more readable/testable and the dynamic nature helps at that a great lot. I personally hate statically typed languages because of the constrains they bring around testing, you have to make some abomination of abstractions to play around the type system, seems like a hack around limitations of the language.

sodapopcan

sodapopcan

That’s interesting. I have heard this before but I’ve never used a statically typed language for a serious project in my life. I recently started writing my Vim plugins in vim9script which statically typed and I did notice a large improvement in the quality of code I was writing, but that’s because legacy vimscript allows you to do some dumb stuff that I would just do because it was what I was used to (and it’s just an editor plugin). I don’t have this pain in Elixir. The 1.17 warnings are very nice, though.

wpiekutowski

wpiekutowski

There doesn’t seem to be any info about the new signatures syntax being added to the language right now or in the near future. I believe it might be added in the future, when/if it’s really needed.

The most recent pieces of info about set-theoretic types seem to be:

sodapopcan

sodapopcan

The spec syntax has been discussed in conference talks and on this forum. I don’t believe it’s officially documented anywhere since it’s basically an “example” at this point. I don’t have any insider info or anything but based on what I’ve heard and read it’ll be a later-stage thing.

matt-savvy

matt-savvy

My advice - just try using @spec and dialyzer for a while; if it starts to feel likea chore, re-evaluate.

The overhead of adding the specs is very low, and the easiest time to add it to a project is in the beginning. If nothing else, you’ll be forced to think for a second or two about the input and output types of your function.

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
jaybe78
Hello, I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter). The diffic...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New

Other Trending Topics Top

garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New
aseigo
ICal is a library for interacting with iCalendar data. It parses iCalendars into typed Elixir structs via ICal.from_ics, and can prepare ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews