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

PragmaticBookshelf
You want increased customer satisfaction, faster development cycles, and less wasted work. Domain-driven design (DDD) and functional prog...
New
AstonJ
More cool tech inspired by <span class="hashtag-icon-placeholder"></span>erlang :nerd_face: By combining the fault-tolerance and massiv...
New
joshi
Hey everybody! I’m working on the project that includes import of Oracle data to PostgreSQL. That data comes as Oracle export (expdp) fi...
New
mafinar
So I was thinking of trying out Crystal, I had tried it multiple times but left it midway. Now that there’s a book on it and it’s version...
New
First poster: dimitarvp
A new Rust blog post/announcement has been posted! Get the full details here: Announcing Rust 1.53.0 | Rust Blog
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
ManningBooks
Rust in Action introduces the Rust programming language by exploring numerous systems programming concepts and techniques. You'll be lear...
New
ManningBooks
Kubernetes in Action, Second Edition teaches you to use Kubernetes to deploy container-based distributed applications. You'll start with ...
New
mafinar
This is going to be a long an frequently posted thread. While talking to a friend of mine who has taken data structure and algorithm cou...
New
PragmaticBookshelf
Develop, deploy, and debug BEAM applications using BEAMOps: a new paradigm that focuses on scalability, fault tolerance, and owning each ...
New

Other popular topics Top

AstonJ
What chair do you have while working… and why? Is there a ‘best’ type of chair or working position for developers?
New
malloryerik
Any thoughts on Svelte? Svelte is a radical new approach to building user interfaces. Whereas traditional frameworks like React and Vue...
New
PragmaticBookshelf
A PragProg Hero’s Journey with Brian P. Hogan @bphogan Have you ever worried that your only legacy will be in the form of legacy...
New
AstonJ
Do the test and post your score :nerd_face: :keyboard: If possible, please add info such as the keyboard you’re using, the layout (Qw...
New
gagan7995
API 4 Path: /user/following/ Method: GET Description: Returns the list of all names of people whom the user follows Response [ { ...
New
AstonJ
Biggest jackpot ever apparently! :upside_down_face: I don’t (usually) gamble/play the lottery, but working on a program to predict the...
New
Maartz
Hi folks, I don’t know if I saw this here but, here’s a new programming language, called Roc Reminds me a bit of Elm and thus Haskell. ...
New
Help
I am trying to crate a game for the Nintendo switch, I wanted to use Java as I am comfortable with that programming language. Can you use...
New
PragmaticBookshelf
Author Spotlight Rebecca Skinner @RebeccaSkinner Welcome to our latest author spotlight, where we sit down with Rebecca Skinner, auth...
New
PragmaticBookshelf
Author Spotlight: Sophie DeBenedetto @SophieDeBenedetto The days of the traditional request-response web application are long gone, b...
New