📎 Webclip
9 Erlang Pitfalls You Should Know About
The post collects nine Erlang mistakes that can stay hidden until runtime and make live systems harder to trust. It argues that careful tests and experience help reduce them, but the main point is to know where Erlang’s syntax and OTP behavior can mislead you.
Reading notes#
- Forgetting the updated state can happen when a value is changed in stages and the last return still uses the old state.
- Reusing a variable name can turn an assignment into pattern matching and hide a mismatch until a real value changes.
- Strings are lists, so list subtraction removes matching elements rather than treating the right-hand value as a substring.
- Guard failures can be silent, including in list comprehensions, so invalid data may be skipped instead of crashing.
- Returning arbitrary
{error, Reason}tuples can create inconsistency unless the surrounding code clearly defines what to do. - Record syntax behaves differently in function bodies and function clauses, because clauses compile into guards and do not check every field.
gen_serverdoes not always callterminate/2; exit trapping and where the exit signal comes from change the behavior.record_info/2is expanded at compile time and cannot be used as a runtime lookup.andandorevaluate both sides, whileandalsoandorelseshort-circuit, so the latter are the safer default.
