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
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
wolf4earth
Serverless has been quite a prevalent topic in our industry in the past few years, and while there are a lot of sceptics, I think it’s sa...
New
New
bot
So you want to live-reload Rust - fasterthanli.me. Good morning! It is still 2020, and the world is literally on fire , so I guess we c...
New
First poster: bot
AbstractMachinesLab/caramel. :candy: An Erlang backend to the OCaml compiler. Contribute to AbstractMachinesLab/caramel development by c...
New
New
New
jaeyson
Sorry for the very vague noob question, I really want to ask this: When do we use async or sync code in the context of Elixir? AFAIK gen...
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
apoorv-2204
I’m experimenting with Hexagonal / Clean Architecture in Elixir. The classic Behaviour + Impl split works great for mocking and isolating...
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
malloryerik
Any thoughts on Svelte? Svelte is a radical new approach to building user interfaces. Whereas traditional frameworks like React and Vue...
New
Rainer
Not sure if following fits exactly this thread, or if we should have a hobby thread… For many years I’m designing and building model air...
New
AstonJ
If you are experiencing Rails console using 100% CPU on your dev machine, then updating your development and test gems might fix the issu...
New
AstonJ
Continuing the discussion from Thinking about learning Crystal, let’s discuss - I was wondering which languages don’t GC - maybe we can c...
New
gagan7995
API 4 Path: /user/following/ Method: GET Description: Returns the list of all names of people whom the user follows Response [ { ...
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
DevotionGeo
I have always used antique keyboards like Cherry MX 1800 or Cherry MX 8100 and almost always have modified the switches in some way, like...
New
PragmaticBookshelf
Author Spotlight: Tammy Coron @Paradox927 Gaming, and writing games in particular, is about passion, vision, experience, and immersio...
New
AnfaengerAlex
Hello, I’m a beginner in Android development and I’m facing an issue with my project setup. In my build.gradle.kts file, I have the foll...
New