<div dir="auto"><div><br><br><div class="gmail_quote"><div dir="ltr">On Thu, Jul 19, 2018, 5:12 AM Chris Angelico <<a href="mailto:rosuav@gmail.com">rosuav@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Thu, Jul 19, 2018 at 4:06 PM, Greg Ewing <<a href="mailto:greg.ewing@canterbury.ac.nz" target="_blank" rel="noreferrer">greg.ewing@canterbury.ac.nz</a>> wrote:<br>
> There's a very long tradition of using the symbol "+" to<br>
> represent addition, so it's something most people are<br>
> familiar with. There's no such tradition for the new<br>
> operators being proposed.<br>
<br>
Okay. What about bitwise operators, then? They don't have centuries of<br>
mathematical backing to support them, yet it isn't considered<br>
"unpythonic" to have &|^~ peppering our code. <br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">I have quite literally NEVER seem Python code with much use of the bitwise operators. I guess the closest I've come is in some NumPy and Pandas code where filters cannot use plain 'and' and ' or' but every student would find it more intuitive if they could. E.g.</div><div dir="auto"><br></div><div dir="auto">myDf[(myDf.field1 > 4) & (myDf.field2 < 2)]</div><div dir="auto"><br></div><div dir="auto">Everyone still gets tripped up by the need for those parentheses because of operator precedence. But this already yells or "special domain" rather than "plain Python".</div><div dir="auto"><br></div><div dir="auto">Indeed, it not uncommon or unreasonable to recommend using np.bitwise_and() to avoid those confusing operators.</div><div dir="auto"><br></div><div dir="auto">In the case where bitwise masking is used in its C manner, the code screams special domain even more loudly. It definitely feels strongly unPythonic, but it's often a reasonable compromise for dealing with just a little bit of binary data without having to write a C extension.</div><div dir="auto"><br></div><div dir="auto">I would ALWAYS want the code that used bitwise operators wrapped in a separate function that most users and developers didn't need to look at, but rather they'd call a more Pythonic API for the overall operation.</div><div dir="auto"><br></div><div dir="auto">A huge difference is that bitwise operators do something you simply cannot do other ways in Python at all. None-aware operators *at best* allow you to write something with an existing straightforward approach using a couple fewer lines. I think the result is ALWAYS less clear to read. Code golf is an anti-goal in Python.</div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
</blockquote></div></div></div>