Skip to content

Consider using Elixir style maps instead of records in Gleam to erlang transpilation #1297

@sidkshatriya

Description

@sidkshatriya

Sorry if this issue has already been considered and definitively decided. In that case please feel free to close the ticket

I understand that gleam uses erlang style records extensively when transpiling to erlang.

Elixir uses erlang maps as a way to define structs. I think there are certain advantages to using maps -- when you see the key __struct__ while tracing you know for sure that it corresponds to an Erlang struct. The same cannot be said about records in erlang -- you cannot be totally sure if a tuple corresponds to a erlang record for sure. Also the keys in a map make understanding things much simpler during tracing/debugging. Whereas in a tuple you need to keep referring back to the record definition, especially if the record has many fields.

Is it too late to consider moving to the usage of maps in gleam transpilation? I'm guessing that maps are bit more resource hungry but there are ecosystem and debugging benefits to using them...

I'm sure a lot of the gleam user base will be coming from Elixir rather than Erlang. Currently to interoperate with Elixir better they might need to use something like https://github.com/QuinnWilton/strucord . We could avoid that entirely if gleam used maps under the hood instead of records. I have very little idea of how that will all work out practically as I've just started exploring gleam.

(I'm also taking the liberty of cc-ing @QuinnWilton in case there are any opinions on this topic -- Thanks in advance!)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions