Erlang / Erlang Basics Interview questions
Why doesn't Erlang have mutable variables?
Erlang was designed around concurrent, isolated processes from day one, and mutable shared variables are exactly what makes concurrent programming dangerous in most other languages — race conditions, torn reads, and the need for locks all stem from two threads touching the same mutable cell.
By making every binding permanent once set, Erlang removes that entire hazard class at the language level: there's no mutable cell for two processes to race over, so there's nothing to protect with a mutex. It also makes reasoning about a function's behavior simpler, since a variable's value can't have silently changed between two lines that reference it.
The design does shift work elsewhere: "updating" a value means creating a new binding (often via recursion carrying an accumulator, or storing the "current" version in ETS/process state), rather than assigning in place. That's a deliberate trade of some ergonomic convenience for much simpler concurrent reasoning.
More Related questions...