Comments (10)
It does seem strange at first with ==
, <=
, >=
being used to do something rather than as comparison operators, but after all it is a DSL so I think it's pretty clear once you use it a few times. Although personally I would use =
in place of ==
if possible (unless you can't overload that one).
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.
from snapkit.
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 if (constraint1 >= constraint2)
Although having said that rather unlikely that you want to compare constraints.
I quite like the idea of substituting =
with ~
~~
>~
<~
~ is usually used to indicate a larger, possibly significant, degree of error.
That sounds like our beloved AutoLayout ;)
A few other possibilities to throw into the mix
---
-->
<--
(looks bit too like a closure?)|==|
|>=|
|<=|
(wrap equality operators)&=
&>
&<
I think ^
could be used to express the priority of a constraint.
@iwasrobbed you can't overload certain operators including the =
operator
from snapkit.
a few examples
installConstraints([
view1.left ~~ view2.left + padding
view1.edges <~ superview.edges - padding
])
from snapkit.
Another possibility: Using ||
for equalsTo
(two plane surfaces attached to each other), >>=
, and <<=
(or >==
and <==
instead)
installConstraints([
view1.left || view2.left + padding
view1.edges <<= superview.edges - padding
view3.edges >>= view1.edges - padding
])
from snapkit.
I would advocate for ==
, >=
and <=
, because in this case the constraints code reads effortlessly. Having used accustomed equality symbols, you will never stumble, thinking "Hey, what is ~~
supposed to mean? Oh right, equality. And what is the symbol for less-than-or-equal-to, again?". I honestly don't think this is confusing because, well, this is DSL, not just your regular code.
from snapkit.
@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
if self.layoutType == Expanded {
view1.left ~~ view3.left + padding
} else {
view1.left ~> view2.left + padding
}
Where as here the line between what is a constraint and what is an equality statement is kind of blurred
if self.layoutType == Expanded {
view1.left == view3.left + padding
} else {
view1.left => view2.left + padding
}
from snapkit.
I like ~~
, to me it looks a bit like "tying the two sides together" 👍
from snapkit.
I agree with @nickynick and using == <= >=
overloaded operators where they make sense are fine, it's when people starting using ==
to combine two objects and return the result or some weirdness.
from snapkit.
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.
It becomes clear that a DSL is used only when the programmer sees the special characters.
I vote for exchanging =
with ~
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 view1.edges.equalTo(xxyy)
still works, right?
from snapkit.
@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
https://github.com/nickynick/Tails and https://github.com/robb/Cartography
from snapkit.
Related Issues (20)
- Low version adaptation problem (12.5.7) HOT 4
- Hey
- J
- The use of SnapKit in a framework is causing a crash HOT 3
- can not call the deinit method
- Apple Vision Pro: No such module 'AppKit' HOT 3
- XCode 15 build SnapKit error HOT 1
- Snapkit
- Try to commit
- Would it be possible to have a new release? HOT 3
- privacy manifest HOT 18
- Why removeConstraints wouldn't call translatesAutoresizingMaskIntoConstraints = true
- How to use SnapKit achieve the following requirements? view.width = (superView.width - 30) * 0.3 HOT 3
- Wtf HOT 2
- Is Snapkit dead?
- Error HOT 1
- Broken github issue template
- Can't download the latest (5.7.0) version with cocoapods HOT 7
- My project supports iOS11 HOT 4
- SnapKit SDK Signature HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from snapkit.