Skip to content
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

Explore alternative syntaxes #4

Open
ghost opened this issue Jan 28, 2015 · 0 comments
Open

Explore alternative syntaxes #4

ghost opened this issue Jan 28, 2015 · 0 comments

Comments

@ghost
Copy link

ghost commented Jan 28, 2015

The current syntax works and is very declarative, but it is kinda verbose. There are several strategies one can find to fix this problem.

One strategy is to simply add more helpers such that some common cases can be come more terse and require less construction of Qt objects. I like the idea of requiring less QObjects a lot, so for example, we could try rewriting this:

Solver {
    Variable { id: var1 }
    Variable { id: var2 }
    Constraint { expr: geq(var2, var1) }
    Constraint { expr: eq(plus(var2, var1), 100) }
    Constraint { espr: leq(var2, 200) }
}

As:

property Variable var1: Variable {}
property Variable var2: Variable {}
property Variable var3: Variable {}
Solver {
    constraints: [
      geq(var2, var1),
      eq(plus(var2, var1), 100),
      leq(var2, 200)
    ]
}

Note that declaring variables like that is already possible (they don't need to be in the solver). I am not sure whether it's a good idea or not. It depends on whether you want/need to expose them to the outside world.

A nother intersting approach, but less QML-ish, would be to use strings instead and parse the expressions, like this:

Solver {
    variables: [ "var1", "var2" ]
    constraints: [
        "var1 >= var2",
        "var2 + var1 == 100",
        "var2 <= 200"
    ]
}

In this later case, the API would need a major revamp, such that one could access the values of these string-identified variables. It lso becomes more tricky to inject values that come with QML, since one need then to manipulate the string somehow, and it might perform worse if constraints change often (which they should not anyways, but...).

@ghost ghost added the help wanted label Jan 28, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

0 participants