Hey Tony,

Thanks, that makes sense.

Part of me feels that it might be a bit heavy-handed to pickle, as the
commands are little more than a name and an argument, arguments being
plain-old-data in this case. Something I think could potentially be
enforced if I continue down this path.

A data-interchange format or protocol sounds reasonable and something I’ll
look into. You’re thinking in terms of a pre-defined dictionary via
something like JSON?

{
    'command': 'create',
    'args': ['age', 5]
}

Best,
Marcus


On 16 May 2014 15:08, Tony Barbieri <[email protected]> wrote:

> You could also use json or another data-interchange format and write a
> simple serializer to reinstantiate your python objects.  Or abstract it to
> support multiple serialization backends.
>
>
> On Fri, May 16, 2014 at 10:07 AM, Tony Barbieri <[email protected]>wrote:
>
>> If you do decide to use python objects you could use pickling as long as
>> you only plan on reusing the history in python.
>>
>>
>> On Fri, May 16, 2014 at 10:02 AM, Marcus Ottosson <[email protected]
>> > wrote:
>>
>>> Hey guys,
>>>
>>> Does anyone have experience using the command 
>>> pattern<http://en.wikipedia.org/wiki/Command_pattern>?
>>> I’m looking for a few things that this pattern seems to help with.
>>>
>>>    -
>>>
>>>    Undo/redo (preferable multi-level and persistent)
>>>     -
>>>
>>>    Action logging (what the user has done, in which order, and where
>>>    things went wrong using which arguments)
>>>     - Distribution of commands via a network (serialisation,
>>>    asynchronous execution)
>>>
>>> I took a whack at it and found it rather straightforward to make a
>>> scripting-language out of it.
>>>
>>> The Command Pattern<https://gist.github.com/mottosso/f5722c4afd1b0791c4d3>
>>>
>>> There’s an example run at the bottom, but the ‘gist’ of it is this:
>>>
>>>      ______________________________________________________
>>>     |                                                      |
>>>     | Command Pattern - Demonstration                      |
>>>     | Author: Marcus Ottosson <[email protected]>  |
>>>     |______________________________________________________|
>>>
>>> * Available commands
>>>     cls
>>>     create
>>>     data
>>>     delete
>>>     exit
>>>     help
>>>     history
>>>     redo
>>>     undo
>>>     update
>>>     verbosity
>>>
>>> command> create key value
>>> command> create age 5
>>> command> create length 1.57
>>> command> data
>>>     age=5
>>>     length=1.57
>>>     key=value
>>>
>>> command> undo
>>> command> redo
>>> command> help update
>>> Update existing value in DATASTORE
>>>
>>>     Args:
>>>         key: Identifier for value
>>>         value: Value for identifier
>>>
>>>     Precondition:
>>>         `key` must already exist
>>>
>>>     Example:
>>>         command> update age 5
>>>
>>> The main questions are about two aspects of it’s design:
>>>
>>> *History is stored as class attributes*
>>>
>>> Which means that commands add themselves to history, which wouldn’t work
>>> too great if they are accessed from separate threads.
>>>
>>> *History is stored as Python objects, as opposed to simple strings*
>>>
>>> Which means that history would be tricky to serialise and persist on
>>> disk or across a network.
>>>
>>> Thoughts?
>>>
>>> Best,
>>> Marcus
>>> --
>>> *Marcus Ottosson*
>>> [email protected]
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Python Programming for Autodesk Maya" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOAc6RTpxT%3Dtppa4GLrvWKZvN_A9qsC0riZQN27NJPcAhQ%40mail.gmail.com<https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOAc6RTpxT%3Dtppa4GLrvWKZvN_A9qsC0riZQN27NJPcAhQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> --
>> -tony
>>
>
>
>
> --
> -tony
>
> --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/CAJhmvsR535D6ZVmnh7jZEsyXzm39FjcuWci5eyRmcACKDPCv9Q%40mail.gmail.com<https://groups.google.com/d/msgid/python_inside_maya/CAJhmvsR535D6ZVmnh7jZEsyXzm39FjcuWci5eyRmcACKDPCv9Q%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
*Marcus Ottosson*
[email protected]

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOC_DyZSO0UOw8pJe6Cbt3%2BmZWTP6yNaTQfehLgxe8sEmQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to