Giter Club home page Giter Club logo

Comments (9)

alice-i-cecile avatar alice-i-cecile commented on June 26, 2024 1

If we end up introducing non-short-circuiting variants, I think those should be the ones to get the longer name, as they're generally going to be dispreferred. Shortcircuiting is a real footgun, but it's rarely stumbled on.

After seeing how run conditions are used in practice, most conditions don't use change detection or event readers, which are the main worry.

We could add docs to the built in combinators that do as well to help warn users?

from bevy.

JoJoJet avatar JoJoJet commented on June 26, 2024 1

I think or_else and and_then are fine. It corresponds to methods on Option with similar behavior so many users will already know how it works, plus it's a non-breaking change to go back to those names

from bevy.

alice-i-cecile avatar alice-i-cecile commented on June 26, 2024

@JoJoJet, spinning this out into an issue. We should resolve this one way or another for 0.15. I definitely agree with your concern, I just don't think that the names are a good way to communicate this :)

from bevy.

JoJoJet avatar JoJoJet commented on June 26, 2024

As evidenced by the fact that users regularly asked "why is it called and_then", and answerers didn't point to "oh that's because it's short-circuiting".

IMO that's the name having its intended effect. The problem is people not answering with the actual reason. The name is supposed to make you go 'huh that's weird, I wonder why it's named like that' so you go looking. If there's a simple name then it's really not clear that there's a huge asterisk when it comes to the system's heavior

from bevy.

CupOfTeaJay avatar CupOfTeaJay commented on June 26, 2024

@JoJoJet
@alice-i-cecile

I would argue that most are using the combinators to just achieve some logical output, that is without taking advantage of the short-circuiting behavior - but maybe there is a better solution here:

Maybe refactor interface to be:

Combinator Short-Circuits Logical equivalent
and No A & B
and_short Yes A && B
nand No !(A & B)
nand_short Yes !(A && B)
or No A | B
or_short Yes A || B
nor No !(A | B)
nor_short Yes !(A || B)
xor No A ^ B
xnor No !(A ^ B)

This has the following advantages:

  • The name of the combinator used explicitly indicates whether or not it is short-circuiting by virtue of the _short suffix. This is much less ambiguous than _then or _else, enough to where I imagine if anybody is curious about what _short means other users who know will probably give the "because it's short-circuiting" answer.

  • No suffixes are added for non short-circuiting combinators. This should be straightforward for users who just want a simple logical output, and the intent (to my understanding) of the original pull request.

Disadvantages:

  • This would probably bloat the interface some more.

from bevy.

alice-i-cecile avatar alice-i-cecile commented on June 26, 2024

For context, the short circuiting is actually mostly a performance optimization, rather than a deliberate behavioral choice.

from bevy.

CupOfTeaJay avatar CupOfTeaJay commented on June 26, 2024

For context, the short circuiting is actually mostly a performance optimization, rather than a deliberate behavioral choice.

Right - that's exactly what I thought. I imagine @JoJoJet 's concern is that perhaps there are users who deliberately want to take advantage of the behavior, and have it not be ambiguous.

from bevy.

JoJoJet avatar JoJoJet commented on June 26, 2024

If we end up introducing non-short-circuiting variants, I think those should be the ones to get the longer name, as they're generally going to be dispreferred

I really don't agree with this. Non short-circuiting should get the shorter name since it's more reliable and generally has fewer considerations. In general, I believe any option that is faster but requires you to know what you're doing should get a longer, more descriptive name

from bevy.

alice-i-cecile avatar alice-i-cecile commented on June 26, 2024

Hmm, fair. Let me bikeshed some names. If we add non-shortcircuiting nicely named variants I think I'm on board.

Candidates:

  • and_short: mysterious, but short to read
  • and_short_circuit: very clear, rather a mouthful
  • and_then: not obvious, same can't be used for or
  • and_&&: is this even legal? It's definitely unidiomatic
  • and_if: short, legible, weird enough to pick up that something weird is going on

I think and_if is my favorite, followed by and_short_circuit. and_short is fine, but meh. Everything else is pretty bad.

from bevy.

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.