In Elixir data is like a rose
I build meaningful software by empathising with design, development and business needs. My interests are test automation, functional programming and full-stack web development using NodeJS and other tools.
Search for a command to run...
I build meaningful software by empathising with design, development and business needs. My interests are test automation, functional programming and full-stack web development using NodeJS and other tools.
No comments yet. Be the first to comment.
Being able to safely refactor code is one of the greatest benefits of writing tests. The goal of refactoring is to improve code design e.g. style, design patterns, performance. Let's take an example from the previous route handler which has already b...

Marginal gains ⚙️ The 2020 Summer Olympic Games were held in Tokyo between 23 July and 8 August. The enduring motto of the Olympics is “Faster, Higher, Stronger”. From 1908 to 2003 the British cycling team won only 1 gold medal at the Olympics. This ...

This is a scenario that took some time to understand. I could see errors in the browser but everything on the server seemed to be configured correctly. The problem was, that when a request was made by the browser, the server handling the request made...

Florida and Minnesota each developed their Statewide Automated Child Welfare Information System (SACWIS). In Florida, system development started in 1990 and was estimated to take 8 years and cost $32 million. As Johnson spoke in 2002, Florida had spe...

Why a health route? I want to begin with the end in mind. When our API is deployed in a cloud environment, the automated, cloud deployment will need a way to know that our API has started correctly. That is the purpose of the GET /health route. I hav...

“A rose by another name would smell as sweet” – Juliet (to Romeo), William Shakespeare’s Romeo and Juliet.
Dear Reader,
Elixir is described as a functional programming language with immutable data but somehow you can rebind the values to a variable. Why is this and how can the data still be called immutable? Let’s start with how it is done.
When we create a variable and assign it a value the computer does two things – it allocates a space of memory to save the value and returns an address to this memory space. We often associate these two operations in the word “variable” i.e. a memory space and its address. In Elixir the value at that memory space never changes but we can reassign the label to a new memory space.
Why it’s done this way can be shown by example.
# pretending we can't change the data at all... age = 12
old = add_one(age) #=> 13 older = add_one(age) #=> 14
This is OK but it can be quite verbose because we need a new label each time we transform the data. To avoid this pattern, and for your convenience, Elixir makes a new copy of the data and rebinds the label in one step.
# new copy, same label age = 12 age = add_one(age) #=> 13
Immutable data is an advantage because it prevents processes that change data competing for the same memory spaces. This competition can causes data corruption, deadlocks and other issues that can be difficult to find and fix.
Sincerely,
Peter