5 ms·
Yes, well known operators like `+` with well known meanings are useful. Why would you write a post about this? Is there some kind of disagreement out there abo
by continuational 7y ago
Yes, well known operators like `+` with well known meanings are useful.
Why would you write a post about this? Is there some kind of disagreement out there about this? I can't think of any popular language that doesn't have it!
Now, consider this instead:
n <> x &~ n
Not only do you not know how to parse this without further knowledge, you also can't pronouce it in a meaningful way or hope to guess what it means.
- csunbird 7y agoIs this legal python?
- ainar-g 7y agoYes. At least in Python 2. "<>" was an alternative spelling of "!=".
- tyingq 7y ago<> is gone in python 3
- JNRowe 7y agoWhen you're unsure about how Python treats an expression, then the ast¹ module is your friend: >>> ast.dump(ast.parse('n != x &~ n'), False) Module([Expr(Compare(Name('n', Load()), [NotEq()], [BinOp(Name('x', Load()), BitAnd(), UnaryOp(Invert(), Name('n', Load())))]))]) It can make it easier to reason through the curiosities, such as the precedence in the given example. Note: Suggesting `ast` as a solution surely proves continuational's point ;) 1. https://docs.python.org/3/library/ast.html https://docs.python.org/3/library/ast.html
- kace91 7y agoAnd it's not easy to Google, which is arguably more important than being pronounceable
- aequitas 7y ago> Not only do you not know how to parse this without further knowledge, you also can't pronouce it in a meaningful way... Therein often lies the problem, if you mentally cannot translate the symbols into meaningful concepts it's hard or impossible to work with them. For example, there are primitive tribes who's language only has words for the amounts of one, two and three. All amounts above that are simply referred to as 'many', no matter if it's four or a hundred. These people cannot (or at least not easily) be thought basic mathematics because they probably can mentally picture 2+2=4 being different from 2+3=5. So if you can find words for these symbols or make up words for your own for that matter and are able to read this expression in these words it will be a lot easier to parse and understand, maybe even intuitively. edit: another example in the Python domain for me would be list and dict comprehensions. When I first encountered them in other people's code I had a hard time understanding what they did. Searching for them was also hard, since I could only describe them (ie: loop within square brackets) and not name them. Finally when I found their name in an reply on SO I was able to search directly for the concepts and find meaningful answers on how to apply them in certain cases.
- clarry 7y ago> Searching for them was also hard, since I could only describe them (ie: loop within square brackets) and not name them. I hope one day someone invents an interactive machine, the user of which can point at a thing and ask "what is this", and get documentation.
- setr 7y agoLike explainshell.com, but as an editor extension?
- gowld 7y agoA new operator is just a letter/word you haven't learned yet. The only things wrong with operators is that non-Asian speakers don't like learning new letters and search engines refuse to index them.
- kccqzy 7y agoSeems easy to parse for people used to working with bit sets in C. The &~ operator is actually two operators frequently used together to do a set difference(†). So it's asking whether n is different from removing all the bits of n from x. The answer is true. †: It's so frequently used that on x86_64 there's a single instruction for that, ANDN. Unless of course you are talking about Haskell and its semigroup combine operator and its lens update operator. In that case the expression can't type check: n has type State s a, x has type s, and n also has type s, which means s is an infinite type and fails occurs check.
- AnimalMuppet 7y agoEven in C bit twiddling, I'd write x & ~n rather than x &~ n The former is much easier to parse (at least to me). ~ is a unary operator, so it's easy to think of ~n as one thing. But &~ is two operators, which I think of as two things, not as one (even if the combination is common).