DEV Community

Discussion on: What Do You Think About Immutable Data?

Collapse
 
dance2die profile image
Sung M. Kim

Robert "Uncle Bob" Martin discussed three programming paradigms in his book, Clean Architecture.

  1. SP (Sturectured Programming)
  2. OOP (Object-oriented Programming)
  3. FP (Functional Programming)

Each one provided programmers "constraints".

  1. SP - A direct/explicit transfer of control (goto is discouraged)
  2. OOP - An indirect transfer of control (function pointers are eliminated)
  3. FP - A variable assignment (cannot assign a new value one initialized)

To understand why immutable data is being popular,
let's see how aforementioned "constraints" help us.

  1. SP - with removal of goto in our code, we can see flow of our code better
  2. OOP- We have a complete control over code dependencies and flows
  3. FP - All race/deadlock conditions, concurrent update problems go away

Front-end world has evolved very quickly and requires many code to run in parallel or asynchronously.
Websites aren't just about onClick-do-this simple any more.
IMHO, immutable data became popular to keep our state in consistent state & also provide other benefits such as memoization, time travel, etc

Collapse
 
solkimicreb profile image
Miklos Bertalan • Edited

Thanks for the awesome comment. I really enjoyed it as a whole but I will highlight a few parts for further discussion if you don't mind.

"to keep our state in consistent state"

This is a bit vague for me. How is mutable state inconsistent?

"All race/deadlock conditions, concurrent update problems go away"

This is true for multi-threaded languages but I don't think this is an issue in case of (the mostly single-threaded) JavaScript.

"also provide other benefits such as memoization, time travel, etc"

I totally agree with this one, immutable updates really shine here.

PS: Thanks for the link to the book.

Collapse
 
dance2die profile image
Sung M. Kim

Thanks for the feedback, Miklos.

This is a bit vague for me. How is mutable state inconsistent?

What I meant was variables don't change thus wherever you access that variable, it's always the same (consistent).
Maybe it came out wrong 😅