Kasun Vithanage
// JavaScript - Mutable array example
function addNumbers(numbers) {
numbers.push(4); // adds to end
numbers[0] = 99; // changes first element
numbers.sort(); // sorts in place
return numbers;
}
const numbers = [1, 2, 3];
console.log('Before:', numbers);
// Before: [1, 2, 3]
addNumbers(numbers);
console.log('After:', numbers);
// After: [2, 3, 4, 99]
// Original array was mutated!
console.log('Original array changed:', numbers);As you can see original data is changed
If we refer this again it may lead to errors
This is common for objects as well
Problem of immutability exists in OOP based languages like Java, C# etc
Solution was to just not mutate original arrays
Which eliminates a whole class of bugs by design
for (let i = 0; i < 5; i++) { // we cant do i++ in Elixir
console.log(i);
}Recursion with Meeseeks
I think we covered enough for today
Let it sink in 🛳️
If its immutable how we can hold state?
Joe Armstrong
📖 Thesis of Erlang
Dr Alan Kay
In Node, if unhandled exception was thrown, it can bring down entire system
Its not about Telecom
We will explore them practiaclly
After you took some Elixir
When i started, i was always asking questions from experts