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

Should comparisons fail fast or provide more flexibility? #6

Open
jamesshore opened this issue Nov 4, 2014 · 2 comments
Open

Should comparisons fail fast or provide more flexibility? #6

jamesshore opened this issue Nov 4, 2014 · 2 comments

Comments

@jamesshore
Copy link
Owner

At present, Quixote fails fast when you make a "nonsense" comparison. For example, if you compare the width of an element to its top edge:

element.assert({
   width: element.top
});

You will get the following exception:

Can't compare width of '#element' to top edge of '#element': Size isn't compatible with Position.

This is a "fail fast" approach. The code is designed to throw an exception when the programmer makes a mistake. Comparing the size of an element to its position is assumed to be a mistake.

Under the covers, positions and sizes are both just pixel values. They can easily be compared. Would we be better off taking out the fail-fast code and allowing the programmer to make "nonsense" comparisons? When would that be useful, and why? What are the tradeoffs?

Discuss this question here.

@mindfullsilence
Copy link

I can see this being extremely useful. For some of our higher profile clients at the agency I work for, we have some pretty intricate style guides that must be followed. For instance, a logo who's left and right margin should be equal to double its top and bottom offset and 1/4 the width of the logo.

@jamesshore
Copy link
Owner Author

Thanks for the feedback. For the example you gave, what do you mean by top and bottom offset? Is it the distance from the logo to the containing element?

We don't have support for margins in yet, but in this case, I'm imagining the assertion might look something like this. I'm assuming the top and bottom offsets are the distance between the edge of the logo and the edge of a containing 'navbar' element:

// Hypothetical
logo.assert({
  marginLeftWidth: [  // array is hypothetical; it means all conditions must be satisfied
    logo.width.times(1/4),  // 1/4 width of logo; this exists today
    logo.top.distanceTo(navbar.top).times(2),  // double the top offset (hypothetical)
    logo.bottom.distanceTo(navbar.bottom).times(2)  // double the bottom offset (hypothetical)
  ],
  marginRightWidth: logo.marginLeftWidth  // the right margin has to equal the left margin
});

Would something like this fit your needs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants