I recently discovered that Java (and Scala) include non-short-circuiting logical operators &, |, and ^. I previously thought these only worked as bitwise operators. While maybe there is an argument for ^, I can’t think of very good reasons for using non-short-circuiting logical operators–although sure, I can contrive an example.
Are these operators useful? They seem more likely to cause hard-to-catch bugs.
scala> def foo = {
| println("foo")
| true
| }
foo: Boolean
scala> def bar = {
| println("bar")
| true
| }
bar: Boolean
scala> foo || bar
foo
res5: Boolean = true
scala> foo | bar
foo
bar
res6: Boolean = true
They’re useful if the right-hand side is a function with side-effects that you want to execute regardless (e.g. logging). However, I would suggest that that’s a bit of a code smell and will certainly be unintuitive to the next guy.