Erlang / Erlang Advanced Interview questions
When should you choose a map over a record for structured data?
Reach for a record when the shape of the data is known and fixed at compile time and you want the compiler to catch typos in field names — classic examples are a gen_server's internal state or an internal domain struct that never gets serialized to an external format.
Reach for a map when the set of keys can vary at runtime, when the data crosses a boundary where records don't make sense (decoded JSON from an HTTP request, dynamically configured options), or when you need to inspect keys generically without knowing the record definition — a function that logs "all fields of this state" can iterate a map's keys directly, but can't easily introspect an arbitrary record's field names without extra metadata.
A common real-world pattern is actually both: define a record for well-known, always-present fields, plus a nested map field within it for optional or dynamically-provided extras, getting compile-time safety on the core shape and flexibility where it's genuinely needed.
More Related questions...