PragTob

PragTob

Elixir is a great language, but some behavior can be unintuitive, confusing and in the worst case lead to bugs. So, I took a look at 10 Elixir gotchas explaining why they exist and how to avoid them!

Showing Posts 1 to 10

BartOtten

BartOtten

Great post.

One more: is_atom(nil) == true as nil is an atom. However, most people mean a defined atom and not ‘undefined’ nil.

PragTob

PragTob OP

Great one! Would have fit well in the current post with all the nil shenanigans but I’ll add it to the list for a follow up!

D4no0

D4no0

The chapter How to use constants is a little bit misleading as module a attributes have not been built to be constant in their design, even though we use them for that.

I agree that a new option for Module.register_attribute/3 to enforce it to be constant would be nice, even though I never saw the immediate need for that as if you respect the fact that you define attributes on top before code, this problem goes away.

PragTob

PragTob OP

I mean, the post mentions that they aren’t actually constant and more of a work-around but also linking to the docs saying to use them as constants. I don’t know how I should make it clearer there while keeping some brevity and not making it the entire topic of the post.

D4no0

D4no0

Ah my bad, you could also point out that a private function can be used for the same thing.

PragTob

PragTob OP

Already updated with that - or well a public function to keep it accessible. I discussed it a bit with José, there are some things that just don’t work without module attributes or would require other workarounds.

michallepicki

michallepicki

Related list collected a few years ago on this forum: Elixir Gotchas and Common Issues Wiki

PragTob

PragTob OP

Some great ones in there, thanks!

dwark

dwark

I got caught off guard by:

 [1, 2, 3] -- [1, 2, 3] -- [1, 2, 3]
[1, 2, 3]

After checking, the docs spell it out neatly once I starting looking for an explanation
(-- is right-associative).

PragTob

PragTob OP

Oh wow, that’s also news to me! Thanks!

I think the great thing about Elixir is that pretty much all of these are well spelled out in the docs :green_heart:

Where Next? Top

Trending in Blog Posts Top

mudasobwa
I am seeing a lot of aplications of Argumentum ad Vericundiam in software discussions. They do link some piece of writing and point us to...
New
bartblast
Hey folks, I just published a post about Hologram’s funding and where the project goes next - the short version: Curiosum as Main Spons...
New
pckrishnadas88
A while back, I had to process millions of database updates in a legacy system that was already hitting its 64 GB RAM limit, so scaling t...
New
rhcarvalho
At the heart of every Phoenix application is the often “invisible” HTTP server layer. For over a decade Cowboy has served the community ...
New
smaller_infinity
I recently figured out how to the the Rust hotpath profiling crate running in an elixir benchmark script (for profiling NIFs). I had some...
New
rhcarvalho
The Phoenix framework is notorious for its long term stability and dependability. Unlike most comparable projects, the Phoenix team activ...
New
pckrishnadas88
I’ve published Part 3 of my Elixir distributed systems learning series. This part explores process monitoring using the low-level primit...
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
webofbits
Aludel - LLM Evaluation Workbench Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews