Your code is hitting the difference between && and and. The former is for logically anding two simple values together within a larger expression; the latter, spelled-out, low-precedence and is for anding together larger expressions, which is what you're doing here. You should be spelling out and in this case. Or, when in doubt, parenthesize.
It may be noted that in practice and is a much more common and useful operator than &&, though both have their uses.
They both short-circuit in the same way, and I suspect that both might also optimize the same way in a parenthesized case, though what gets optimized is really an internals issue that does not make a lot of difference at the language level. (In your code, if the 1 && were not optimized away, the result would still be the same and would still not be what you want. The optimization is just an implementation detail.)
There are languages that are largely immune to this sort of issue, due to not having complex precedence tables. Most lisp-based languages fall into this category: Common Lisp, Scheme, elisp, and so on. But to work with those languages, you really NEED an editor that does paren matching or automatic indentation -- preferably both.
In reply to Re: Short Circuit Operator and Hash Assignment
by jonadab
in thread Short Circuit Operator and Hash Assignment
by periapt
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |