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

JEG2
I’m closing out, for now, my series on questions at the heart of development with an analysis of when we need more abstraction. For exam...
New
New
mudasobwa
Blogged about the motivation and reasoning behind my idea to create yet another FSM library. Long story short: I did it in a proper way :...
New
paulanthonywilson
All a bit meta, but this is a quick post on creating a Jekyll blog post from a Livebook page. Posted via Devtalk (see this thread for ...
New
brainlid
On your LiveView page, you are using a custom component. You want to be able to pass HTML attributes into the component, but the componen...
New
marcin
Hi! :wave: I wanted to refresh my knowledge on how to mix phx.gen.auth with local password users db, as well as OAuth providers such as ...
New
ErlangSolutions
An infographic that compares Erlang, Elixir, and Go's strengths in the respect to the programming languages' concurrency, reliability, sc...
New
New
New
davydog187
Hello all! I wrote a blog post called Elixir Observability: OpenTelemetry, Lightstep, Honeycomb. The post post covers how to integrate ...
New

Other popular topics Top

senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
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
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
magnetic
Hey :wave:t3: Elixir community, I’ve been learning Elixir, and working on some side projects. My editor of choice is VSCode, and althoug...
New

We're in Beta

About us Mission Statement