GithubHelp home page GithubHelp logo

Comments (10)

iwasrobbed avatar iwasrobbed commented on May 3, 2024

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.

cloudkite avatar cloudkite commented on May 3, 2024

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.

cloudkite avatar cloudkite commented on May 3, 2024

a few examples

installConstraints([
    view1.left ~~ view2.left + padding
    view1.edges <~ superview.edges - padding
])

from snapkit.

iwasrobbed avatar iwasrobbed commented on May 3, 2024

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.

nickynick avatar nickynick commented on May 3, 2024

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.

cloudkite avatar cloudkite commented on May 3, 2024

@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.

ahti avatar ahti commented on May 3, 2024

I like ~~, to me it looks a bit like "tying the two sides together" 👍

from snapkit.

robertjpayne avatar robertjpayne commented on May 3, 2024

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.

joachimboggild avatar joachimboggild commented on May 3, 2024

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.

cloudkite avatar cloudkite commented on May 3, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.