-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Explain reasoning behind avoiding mutation #27
Comments
Here's my take ethereum/py-evm#1421 (comment) |
Making the RLP objects immutable had some really cool effects, but I don't have it distilled down to a clear story right now. Fleshing that out could be a great case study into why we prefer immutable objects. I roughly recall benefits like:
|
We can come up with a simple (artificial) code example that crashes at runtime because code place X has a reference to Y where Y qualified some condition at the time of verification but then crashes when it is being used later because the condition changed because of some mutation. Not real world code but just to give a code example that demonstrates how mutation imposes such risks. |
From a theoretical point of view, expressing things in terms of immutable objects makes it easier to relate the implementation of an algorithm to its mathematical definition. I believe mathematicians tend to avoid the use of mutability when formally defining algorithms. |
A good example of when immutable objects can be a true evil: ethereum/trinity#182 |
We need a section which explains the reasoning behind why we avoid mutation in our code:
see: ethereum/py-evm#1421 (comment)
It would be really nice if it included code examples for non-mutative approaches to common patterns that are typically accomplished using mutation.
The text was updated successfully, but these errors were encountered: