Hello everyone, I wrote a small draft for proposing state immutability through a mechanism consisting in const objects, functions and parameters.
What do you think? I hope we can elaborate it more
Hello everyone, I wrote a small draft for proposing state immutability through a mechanism consisting in const objects, functions and parameters.
What do you think? I hope we can elaborate it more
Before stage 2, proposals are primarily problems that need to be solved. What problems is this solving? I couldn’t find any motivation in the readme.
I think you are right and I will do my best to further enrich this draft, thank your for your feedback. I will update it adding recurrent problems and how this mechanism can benefit
The main problem with immutability is carving out exceptions. Fully immutable / pure functions don't get you very far and are very constraining. Often you need them to effect the arguments for example. The question that raises is how can the engine determine what state can be modified and which cannot.
Your examples rely on private fields, but that isn't the only kind of attached state. Some object may use closures, other weakmaps. What does it mean for an object to have immutable state? Can it no longer be used as a Map key? Can an immutable function reference closed over state?
I find that the usefulness of immutability is for the caller to ensure that some function it calls will not effect the execution besides through it's return value. As such I would like to explore something around write barriers and invocations with side-effect guards. However I don't know how to solve allowing mutation to a subset of cases like some arguments or enabling constructs like memoization.