|
I disagree. Just because it's unfamiliar and hence "jarring" does not, of itself, means it's obfuscating. I agree that code should be written at the highest level possible to express the intent, but sometimes that's not possible. In this case it's likely that performance wasn't an issue, and this particular idiom is actually of no value, but I contend that the principle remains: an idiom need not immediately be clear, and yet can still sometimes be the right thing to do/use. Your last point is simply acknowledging that this is an idiom - what you say is characterising what an idiom, as opposed to an expression, is. It's not what you might expect, it's short, it accomplishes its purpose. Finally, and again, I say that this particular example may not be a good one, but I say again that sometimes idioms are appropriate. You may disagree, but you haven't persuaded me. Our experiences no doubt differ, and may be the root cause. |
It’s clear that using the bitwise or operator adds some bit of mental overhead, at least the first few times the reader looks at it, while floor is completely obvious and clear to the average novice programmer. This mental overhead slows the reader down, and makes the code harder to understand. If it’s just one line like that every few hundred lines, or some optimization in an inner loop that is clearly commented, that’s not a problem. But code written by someone who has decided that all of their tricky lines that first look like one thing but actually do something unexpected are actually wonderful “idioms”, is code that can become a serious pain in the ass for whatever poor sap has to build on top of it or fix its bugs.