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.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
