vvvv / VL-Language

The official repo for the design of the VL programming language
31 stars 0 forks source link

[Quest] Design patterns for switchable Behaviors: Automata & the Strategy pattern #8

Open gregsn opened 4 years ago

gregsn commented 4 years ago

There are behaviors that are too complex to be modeled just with one patch:

In these situations, it can be easier to think in system states, embrace them, and make them first-class. This is what an Automaton does. You define system states, give them names, and try to figure out how to get from "start" to "done".

Thinking in these states can make you focus on one thing at a time, which suddenly makes your system more readable/approachable/writable/debuggable. Now after scribbling your different modes the big question arises on how to patch systems like this with VL.

There are different approaches for working with automata from within vvvv beta. But they all come with the idea that you

Examples:

In VL however, another option arises, which might feel much more natural (TBD)

tebjan commented 4 years ago

for reference: https://github.com/danielgerlag/workflow-core

it allows building workflows with LINQ-like fluent programming and includes state handling:

public class MyData
{
    public string Email { get; set; }
    public string Password { get; set; }
    public string UserId { get; set; }
}

public class MyWorkflow : IWorkflow
{
    public void Build(IWorkflowBuilder<MyData> builder)
    {    
        builder
            .StartWith<CreateUser>()
                .Input(step => step.Email, data => data.Email)
                .Input(step => step.Password, data => data.Password)
                .Output(data => data.UserId, step => step.UserId)
           .Then<SendConfirmationEmail>()
               .WaitFor("confirmation", data => data.UserId)
           .Then<UpdateUser>()
               .Input(step => step.UserId, data => data.UserId);
    }
}

also this one, it is cross-platform and can read Microsoft workflow files: https://github.com/UiPath-Open/corewf