AstonJ

AstonJ

Do you say 'unpack' or 'destructure'?

Consider this Erlang code:

Rectangle = {rectangle, 20, 10}.
{rectangle, Width, Height} = Rectangle.
> Width.
20
> Height.
10

When I was watching an Elixir video the person kept calling this ‘destructuring’ (which I think is what they say in the JS world?) but Joe Armstrong, in his book Programming Erlang, calls this ‘unpacking’ - so I am curious, how do you refer to it when using a BEAM language?

  • Unpack
  • Destructure
  • Use the terms interchangeably depending on the language
  • Something else - please say in thread!

0 voters

Most Liked

chriseyre2000

chriseyre2000

Technically it’s pattern matching since we can be more specific by repeating a variable to ensure that it is used in multiple places.

Eiji

Eiji

Object : typeof instance === "object". Special non-data but Structural type for any constructed object instance also used as data structures: new Object, new Array, new Map, new Set, new WeakMap, new WeakSet, new Date and almost everything made with new keyword;

Source: JavaScript data types and data structures - JavaScript | MDN

This quote shows us that equivalent/similar data types across languages are implemented and therefore grouped differently which means that we can’t use exactly same naming. Different naming forces new developer to think: Why it's named like that? and that ends up with looking for it’s definition.

The destructuring assignment syntax is a JavaScript expression that makes it possible to unpack values from arrays, or properties from objects, into distinct variables.

Source: Destructuring assignment - JavaScript | MDN

Having in mind that both destructure and unpack are used only for arrays and objects it’s confusing to use them in Elixir for other data types like for example string. Destructure naming could also be confusing for newbies as we have structs.

Destructure and unpack antonyms suggest that we have something structured or packed which is not always true. While it’s common to say that we are unpacking bits from string still we can’t say that we are unpacking something from literal like for example: 5 = variable.

Generally i.e. for all data types I prefer to think about some connection of assignment, fetch, pattern and take words (which are most common) like taking by pattern or something like that.

@AstonJ Considering your Erlang code we can say that we are taking items: rectangle, Width and Height by 3-element tuple pattern of Rectangle variable. What do you think about it?

Popular Backend topics Top

New
New
New
bot
Announcing the Error Handling Project Group | Inside Rust Blog. Want to follow along with Rust development? Curious how you might get in...
New
pillaiindu
I have heard many times that languages with a garbage collector aren’t great for system programming. Today I saw a book titled “Hands-On ...
New
First poster: bot
This Python script mimics Babbage’s Difference Engine. In Use this Python script to simulate Babbage’s Difference Engine, Python offered...
New
ariandanim
Hello, i am facing difficult using webpack when to install within phoenix framework 1.5.7 because the webpack is still version 4.x.x inf...
New
kelvinst
I have being some Elixir open-source contributions and side projects. Oh, and I’m doing them on livestreams on my twitch channel, follow ...
New
New
luigiluigiluigi
Hey everyone! :wave: We’re looking for a Back-End Developer Volunteer to help us build something impactful! If you want to gain real-wor...
New

Other popular topics Top

AstonJ
If it’s a mechanical keyboard, which switches do you have? Would you recommend it? Why? What will your next keyboard be? Pics always w...
New
axelson
I’ve been really enjoying obsidian.md: It is very snappy (even though it is based on Electron). I love that it is all local by defaul...
New
Exadra37
On modern versions of macOS, you simply can’t power on your computer, launch a text editor or eBook reader, and write or read, without a ...
New
AstonJ
This looks like a stunning keycap set :orange_heart: A LEGENDARY KEYBOARD LIVES ON When you bought an Apple Macintosh computer in the e...
New
AstonJ
In case anyone else is wondering why Ruby 3 doesn’t show when you do asdf list-all ruby :man_facepalming: do this first: asdf plugin-upd...
New
mafinar
Crystal recently reached version 1. I had been following it for awhile but never got to really learn it. Most languages I picked up out o...
New
New
Margaret
Hello everyone! This thread is to tell you about what authors from The Pragmatic Bookshelf are writing on Medium.
1134 25373 750
New
First poster: bot
The overengineered Solution to my Pigeon Problem. TL;DR: I built a wifi-equipped water gun to shoot the pigeons on my balcony, controlle...
New
First poster: bot
Large Language Models like ChatGPT say The Darnedest Things. The Errors They MakeWhy We Need to Document Them, and What We Have Decided ...
New