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?

Where Next?

Popular Backend topics Top

AstonJ
Thought this video was interesting: What are your thoughts? Any areas you agree/disagree? Which web-dev tech do you think is worth ado...
New
AstonJ
Partly interested in this so we can set up tags, but also because I’m out of touch with which frameworks are hot right now and I’m curiou...
New
New
New
AstonJ
Inspired by this post by @stefan.jarina, I’m curious about the kind of Bash scripts you’ve written and whether you still use Bash given t...
New
rustkas
Intensively researching Erlang books and additional resources on it, I have found that the topic of using Regular Expressions is either c...
New
Reinis
I’ve been diving into Bridgetown (a Jekyll successor) and learning about writing a more maintainable CSS.
New
jaeyson
Hey! Just a random thought though: Found an article from fudzilla where AI can be a good debugger. How does one integrate something like ...
New
mafinar
December is only a few weeks away. I have been detached from programming puzzles for a while now so thought I would give myself some warm...
New
pillaiindu
Hi everyone, Does anyone know when will “Agile Web Development in Rails 8” by Pragmatic Bookshelf release. I’m eager to dive into the la...
New

Other popular topics Top

AstonJ
Or looking forward to? :nerd_face:
New
brentjanderson
Bought the Moonlander mechanical keyboard. Cherry Brown MX switches. Arms and wrists have been hurting enough that it’s time I did someth...
New
AstonJ
Curious to know which languages and frameworks you’re all thinking about learning next :upside_down_face: Perhaps if there’s enough peop...
New
AstonJ
There’s a whole world of custom keycaps out there that I didn’t know existed! Check out all of our Keycaps threads here: https://forum....
New
AstonJ
I’ve been hearing quite a lot of comments relating to the sound of a keyboard, with one of the most desirable of these called ‘thock’, he...
New
AstonJ
I ended up cancelling my Moonlander order as I think it’s just going to be a bit too bulky for me. I think the Planck and the Preonic (o...
New
Exadra37
I am asking for any distro that only has the bare-bones to be able to get a shell in the server and then just install the packages as we ...
New
PragmaticBookshelf
Author Spotlight Jamis Buck @jamis This month, we have the pleasure of spotlighting author Jamis Buck, who has written Mazes for Prog...
New
PragmaticBookshelf
Author Spotlight: VM Brasseur @vmbrasseur We have a treat for you today! We turn the spotlight onto Open Source as we sit down with V...
New
AstonJ
This is cool! DEEPSEEK-V3 ON M4 MAC: BLAZING FAST INFERENCE ON APPLE SILICON We just witnessed something incredible: the largest open-s...
New