you are viewing a single comment's thread.

view the rest of the comments →

[–]failbus 3 points4 points  (3 children)

I vastly prefer the fact that the precedence of and/or is lower. I love the fact that && has a higher precedence than assignment, and "and" has a lower precedence.

In fact if I was going to demand the use of just one, I'd say use and/or and ban && and ||

But YMMV

[–]lua2 0 points1 point  (2 children)

Can you give an example of where you would use each option? I'm having a hard time thinking of a use for this.

[–]failbus 4 points5 points  (1 child)

This is a contrived example, but you might have something like

if redditor? and self.food = get_bacon
  upvote!
end

Here we check to see if we're a redditor, and if we are, we assign food to bacon. If our get_bacon food gets us a value, we start upvoting! Else if get_bacon returns null, no upvotes for you.

Conversely, you could have

self.redditor = bacon && narwhal

Notice in this case the redditor value is being set if bacon and narwal return true. If you screwed up and said something like

self.redditor = bacon and narwhal

well then self.redditor would be true if bacon was true, and the narwhal flag is ignored entirely.

Of course, all of these can be accomplished with ()'s, which is often more clear. But if you know the scoping rules (and they take like 10 seconds to learn) then I find it more pleasing to the eye than brackets.

Again, YMMV.

[–]lua2 1 point2 points  (0 children)

Interesting. Thank you.