zachdaniel

zachdaniel

Creator of Ash

Blog Post: Serialization is the Secret | If a value mutates in the forest with no one to see it, does it really mutate?

In this post I discuss what immutability means in the context of Elixir, and the properties that stem from it.

Most Liked

BartOtten

BartOtten

A bit more explanation would be: each variable points to an exclusive memory location which can not be mutated. A new variable (even when named the same) is a new exclusive memory location.

The blog does a good job of explaining that Elixir numbers the variable names internally, so the second ‘varname’ is in fact ‘varname2’ underneath and so no the same variable.

Nitpick: The example with the rookie mistake is not that clear at first sight. @zachdaniel might want to either explain it a bit more why it does “ surprising stuff” or replace it with another variant, as for me it does exactly what I expect it to do (just not from an immutable view). One that bit myself once: have a list of date ordered scores [1,5,2], send it to function top_score to pick the top score by sorting [1,2,5] it and give me the top result 5, continue with the list below the call to top_score(list) expecting it to be the original date sorted [1,5,2]….auch. In this example the function was never expected to mess up the list order ‘globally’.

As Javascript is large in React, the sorting function would cause a unexpected rerender due to the change.

derek-zhou

derek-zhou

Very nicely written. To summarize: Mutation depends on the point of view; Unobservable mutations do not count; Mutations can only be observed through indirect observation, such as an impure function call.

sodapopcan

sodapopcan

This mutation, however, is syntactic.

Wish I’d been armed with this simple explanation in some past discussions :sweat_smile:

Where Next?

Popular in Blog Posts Top

mudasobwa
Just blogged on the general approach to creating easily extendable applications with plugin support.
New
blackode
https://medium.com/blackode This article comprises of two biggest changes of ExUnit. Arguments in the failure report Running mix tes...
New
paulanthonywilson
So you’re enjoying using WebSockets with Elixir’s Phoenix Framework, and you want to send some binary messages. Maybe it’s an audio clip,...
New
brainlid
Elixir has a built-in Zip library that comes with OTP. This post explores how to use the zip module and asks the important question: “Is ...
New
gaggle
This post explores different ways to do test automation in Elixir, focusing on how to handle dependency injection — covering patterns, li...
New
brainlid
You are storing some Phoenix LiveView state in the browser. You want to retrieve that saved state as early as possible to improve the use...
New
brainlid
I love LiveView. Navigating between views is so fast! This quick tip makes navigating feel instantaneous by adding a split-second delay b...
New
ryanrborn
A long-running GenServer holds orders, positions, strategy state, and operational flags for a system trading real capital. The post walks...
New
brainlid
Jason Stiebs shows a couple ways for a LiveView to make it easy for users to click and copy an important value to their clipboard. He sho...
New
Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 127089 1222
New

Other popular topics Top

siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement