-
Notifications
You must be signed in to change notification settings - Fork 2k
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
What operators should the DSL use? #1
Comments
It does seem strange at first with My vote would be to use those operators rather than prefixing them with another character and just assume a short learning curve at the cost of immediate clarity for new users. |
The other downside to using equality operators is that it will take away the ability to use them for actual comparison ie you won't be able todo I quite like the idea of substituting
That sounds like our beloved AutoLayout ;) A few other possibilities to throw into the mix
I think @iwasrobbed you can't overload certain operators including the |
a few examples
|
Another possibility: Using installConstraints([
view1.left || view2.left + padding
view1.edges <<= superview.edges - padding
view3.edges >>= view1.edges - padding
]) |
I would advocate for |
@nickynick I agree it would a bit harder to digest at first. However it does have the advantage of clearly distinguishing layout constraint equations from equality statements. Consider the following code
Where as here the line between what is a constraint and what is an equality statement is kind of blurred
|
I like |
I agree with @nickynick and using |
A comment: @nickynick and @robertjpayne : It might not be clear to a developer that he is in fact using a special "language"/DSL in these specific lines of code, and for that reason using the equality operators should be avoided. Another thing: The overloaded operators are not obvious when using code completion - I hope that these operators are not the only way to specify the relationships? The "old" way with |
@joachimboggild Yup we decided to keep this repository as a swift version of the Masonry syntax since there are already a couple of good options for operator overloading see |
This is a (imho) pretty important design decision: What operators do we use for expressing constraints?
There are basically three different kinds of operators needed. One for expressing the kind of relationship, another for the factor and one for the constant.
For factor and constant, I would say that
*
,/
and+
,-
are simple and good choices, since they express perfectly well what they are supposed to do.For the kind of relationship I am not sure.
We could use
==
,<=
,>=
. These are understandable, but have (again, imho) one problem: They are seldom, if ever, used to do something. Usually, they are always only used to test for something, and do not, in and of themselves perform any action (such as creating a constraint).So the alternative is to come up with another set of operators different from the comparison operators, and thereby make it clear that these are not normal comparisons and do in fact do something.
I think what this decision boils down to is the following question:
Does the programmer describe a set of checks that the system then tries keep true, or does he explicitly create constraints? Does he say "this attribute should always be equal to that attribute" or does he say "make this attribute equal to that attribute"?
PS: If we choose to invent new operators, we have these characters to play with:
/ = - + * % < > ! & | ^ . ~
, and I would say it'd be a reasonable choice to take==
,<=
,>=
and prefix them with one of those characters.The text was updated successfully, but these errors were encountered: