A real-life example that I encountered not so long ago was related to parse things from OTP’s :public_key module: x509/lib/x509/public_key.ex at v0.8.9 · voltone/x509 · GitHub , even though in lots of cases you can get away with having records, sometimes you want a fast and dirty solution by using elem/2 .
I also think that we in elixir always tend to use alternative like lists instead of tuples for structured and ordered data, and honestly a lot of designs could benefit a lot by using tuples.
I also had no idea that records were so useful, I encountered them a few times in the wild while trying to port erlang records to elixir and I always thought that this is just a interoperability bridge but it seems they can be very useful, I will most probably start incorporating them in my code from now on.
Thanks for more examples! :public_key doesn’t appear to be in the standard lib but I take it :public_key.pem_decode returns a pem/rsa file as a tuple of lines? If so, I think I’m getting it. I’m primarily an application developer and I just couldn’t understand why you would ever not know the length of the tuple you were working with and why you would ever have a one longer than 3 or 4. I definitely need to work on my phrasing when asking questions.
I don’t know what you consider standard library, for me everything included in elixir and OTP is standard library, :public_key powers things like :ssl.
You always know the length of a tuple, but you don’t want necessarily to match on the tuple, simply because this becomes horrible once the tuples are huge and nested, so this is where you ideally use records or elem/2.
No that’s what I mean, but there seems to be a possible autocomplete bug in iex. Typing :us<tab> will autocomplete :user_ but typing :pub<tab> does nothing. However, if I type out :public_key. in full then hit tab, it shows me the functions. And only after typing the module in full it will start to auto complete. In any event, :pub<tab> was all I tried last night which made me think it wasn’t in stdlib
That is weird. I have the same behavior. I can not let this go. Why does :pub not “tab out” to :public? There must be a reason.
Update: I think I got it https://www.erlang.org/doc/man_index.html
Any module that is Application “kernel” or “stdlib” or “erts” will tab out.
Otherwise it will not.
:public_key is in its own “public_key” application.
Similarly, :pretty_pr, :os_sup and :release_handler will not tab out.