Ruby Demystified: and vs. &&
blog.tinfoilsecurity.com
Ruby Demystified: and vs. &&
1–10 of 74 posts
Re: Ruby Demystified: and vs. &&
#2Significantly, "&&" > "=" > "and", which can lead to unintended results when refactoring "&&" --> "and"
Re: Ruby Demystified: and vs. &&
#3tldr: && has higher operator precedence than "and" Significantly, "&&" > "=" > "and", which can lead to unintended results when refactoring "&&" --> "and"
Re: Ruby Demystified: and vs. &&
#4Re: Ruby Demystified: and vs. &&
#5Seeing "and" or "or" in Ruby code now leaps out at me with danger signs. I've decided it's just not worth it.
Re: Ruby Demystified: and vs. &&
#6First, in Python, there's only one way to express a boolean "and". The && operator is left out.
Second, this post demonstrates a danger of allowing assignment via '=' evaluate to an expression (granted with less weird precedence rules it wouldn't turn out as bad in this case).
Re: Ruby Demystified: and vs. &&
#7 pry(main)> a = true && false
pry(main)> a = true and false
Hmm...I dunno, I don't think the latter is necessarily easier to read than the former. The use of the symbols helps, for me at least, to delineate between value/variables and operators. Those symbols aren't pretty but their ugliness can serve a purpose.I don't mind using them in SQL, but only because SQL is case-insensitive and I can stick to the style of making all syntax uppercase.
Re: Ruby Demystified: and vs. &&
#8 $fh = open() or die("File did not open")
Instead of: $fh = open()
die("File did not open") unless $fh