PragTob

PragTob

Blog Post: 10 Elixir gotchas

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!

First 10 of 44 Posts Switch mode

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?

Trending in Blog Posts Top

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
ryanzidago
Hi all, In this article, I make the case for each test owning its setup. Usually I forbid my AI agents to use the setup callbacks; I mu...
New
zorn
As I’ve leaned into AI code generation on LocalCents, the volume I ship has climbed, and my worry shifted from any single change to the l...
New
jswanner
I wrote about an issue I had with a LiveView application, and how I solved the problem by debouncing updates server-side (within the Live...
New
abreujp
I’ve published a new article in my Elixir learning series on dev.to exploring what happens when tagged tuples aren’t enough - the try, re...
New
pckrishnadas88
This article demonstrates how to build a minimal stateful process using only Elixir’s core concurrency primitives: spawn/1, send/2, recei...
New
zorn
A recent ex_money v6 upgrade was blocked because Timex pins an old gettext. Rather than one big remove-and-rewrite PR, I used a shim: a m...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
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
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New

We're in Beta

About us Mission Statement