P
P
Panfilov2015-04-07 10:55:57
Algorithms
Panfilov, 2015-04-07 10:55:57

What can be read on immutable data types (mutable/immutable data)?

Good afternoon.
There is an understanding of the existence of mutable and immutable data structures.
There is no understanding how and due to what immutable types are "better"? What are the disadvantages of immutable types?
What is the life cycle of types and their difference?
Is there any literature on this?
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
lo-fi, 2015-04-07
@Panfilov

Undoubtedly, for a good understanding of immutable structures, it is worth familiarizing yourself with functional programming languages. In this case, Clojure would be a better choice (versus Scala) - where the idea of ​​persistent immutable data structures runs through the entire design of the language.
In a nutshell, immutable data structures are better because of the guarantees that they cannot change. I explain. Because Since in modern programming languages ​​it is customary to pass arguments to a function by reference, then there is no way to assert that the method has not changed the collection or any other structure. This is especially true for third-party code.
Also, this immutability guarantee forces one to more carefully design algorithms and APIs of concurrent environments, instead of hastily changing the state of some shared structure from different threads of execution (shared mutable state is generally evil when writing concurrent code).
In a completely abstract way, immutable data structures change the design of the program from (shared mutable data + code that changes this data) to (immutable data in contexts + pure functions).
The disadvantages include an additional load on the garbage collector, tk. for one changed field in the structure, an additional copy of this structure is created (of course, without duplicating structures by reference, since the contents of these structures cannot change). It's not exactly a minus, but the design. Well, to create immutable data structures with a convenient API in imperative programming languages, you need to write a little more code (in actual functional languages, the vast majority of structures are immutable).
You can read it here tonsky.me/talks/2015-codefest

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question