Undo?

Mr. Jonse Jonse at Theory.uni
Tue Oct 10 02:36:56 UTC 2017


I requiring an undo feature in my code. Rather than go the 
regular route of using commands, I'm wondering if D can 
facilitate an undo system quite easily?

We can think of an undo system in an app as a sort of recorder. 
The traditional method is to use commands and inverse-commands. 
By recording the commands one can "unwind" the program by 
applying the inverse commands. The down side is that the app must 
be written with this approach in mind.

Storing the complete state of the app is another way which some 
apps use but usually it is too much data to store.

Since the only thing that one has to store from state of the app 
to the next is the change in data long with creation and deletion 
of the data, I think one could simplify the task?

Is it possible to write a generic system that records the the 
entire state changes without much boilerplate?

I'm thinking that two types of attributes would work, one for 
aggregates for creation and deletion of objects and one for 
properties to handle the data changes. If D can be used to 
automatically hook properties to have them report the changes to 
the undo system and one can properly deal with object creation 
and assignment, it might be a pretty sleek way to support undo.


Help appreciated!




More information about the Digitalmars-d-learn mailing list