Post

When to name your #ElixirLang function with a bang? Only if the function is *expected* to throw errors during normal execution. Do not simply 'inherit' bangs from what’s inside that function (`Repo.update!`) if those exceptions would signal a bug (that is, should never happen).

4 reposts26 likes

Yeah, that's a good advice. I like to think of a bang as a wrapper around a non-bang. So in a bang, we call the non-bang, and then wither unwrap the ok tuple and return just the result, or raise an error. Which means that bang only makes sense when there's a non-bang version.

I never thought about this and always "inherited" the bang, but you are right! From now on, I'll use a bang only if the exception is expected and will use no bang if an exception would indicate a bug. Thanks for sharing!