Chris, The 0.5x Engineer @llcoolchris.dev · Oct 29

Alright GANG #ElixirLang, what do we think about this pattern? See dev.to/martinthenth...

5 likes 8 replies

?

Replies

Saša Jurić · Oct 30

Hard pass. I dislike how things which are strongly related (validation and the corresponding error) are separated so far apart. This is what I do instead 👇

Elixir ▷ Max · Oct 30

I'm aware of this pattern but never needed it, as I prefer functions that return :ok | {:error, reason} as opposed to a boolean. Booleans are simply not informative enough, I don't like them :)

Paweł Świątkowski · Oct 30

It's fine IMO, but I've seen it abused to a point of code being completely unreadable. I'd only use it for simple cases like this - short function names with 1-2 arguments. But I really like what @sasajuric.bsky.social proposed here as the alternative: bsky.app/profile/sasa... It's way better.

Jacob Chae · Oct 30

I don't dislike it. I think it might be difficult to read in more complicated cases though.

Daniel Hoelzgen · Oct 30

I like that it works, but I can imagine it getting hard to read if used excessively for complex scenarios and in the other involved functions, too.

Zach Daniel · Oct 29

Works for me :) I’ve seen people suggest it’s a bad idea, but I don’t see why personally.

Hauleth · Oct 30

Nah, if you need something like that, then you probably need to rethink your API a little bit.

Tyler A. Young ⚗️🧑🏻‍💻 · Oct 30

Fine when used sparingly. Definitely less readable than if you can get away without the tagged tuples, but sometimes you legitimately do need different error handling for different failure cases, and the alternative of 6 levels of nested case statements or single-use private functions is worse.