
There are orders of precedence at work here, but also some subtle ones that might not be clear. `and` and `&&` have different precedence. Likewise `or` and `||`. And I cannot count the number of times that I have tried to be all minimal and introduced a logical error in my code. Only staring at it long enough made it clear to me that a whole branch of my comparison was being ignored. I personally tend to put lots more parentheses in than might strictly be needed, and I treat them as if they were comments -- they explain visually what I am imagining the grouping to be. And sometimes that turns out to be necessary in order for it work the way I expect it to. A good question to ask yourself: would this be clearer as two lines? What would those two lines be? Could you use `return foo if 1 and 2` to short-circuit it? Not an answer, but maybe a way for you to interrogate the question from a different angle. Walter
On Feb 17, 2024, at 2:04 PM, Information via ruby-talk <ruby-talk@ml.ruby-lang.org> wrote:
Hi
p(1 and 2 or 3 and 4)
1. how many brackets do we need?
2. in my opinion the result should be 2, not 4.
What do you think?
Andreas
______________________________________________ ruby-talk mailing list -- ruby-talk@ml.ruby-lang.org To unsubscribe send an email to ruby-talk-leave@ml.ruby-lang.org ruby-talk info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-talk.ml.ruby-lang.org...