3 ms·
Since you apparently know stuff about language, maybe you can help me out: Sometimes novice programmers try something like "foo == bar && baz" when they really
by LambdaComplex 9y ago
Since you apparently know stuff about language, maybe you can help me out:
Sometimes novice programmers try something like "foo == bar && baz" when they really should have "foo == bar && foo == baz". This is because, in English, "Foo is equal to bar and baz" means (and is more common than) "Foo is equal to bar and foo is equal to baz". There's some name for this rule, but I haven't been able to remember it for a while. I think it's "right hand ______", but I can't remember that final word.
- evincarofautumn 9y agoFirst, I have a little anecdote about that. I was at a summer camp where we were taking game programming classes. I had been programming for longer than the other students, so I would help them out. One of my peers asked me for help with a part of his program. In the course of that, I noticed that he had written “if (x == 1 || 2 || 3 || …)” in another part of his code, and explained that this condition would always be true (in C++). He became defensive and dismissed me, saying “nah, I tried it and it works”…because he had only been trying the success cases. It absolutely infuriated me! Anyway, IIRC that pattern is called “conjunction reduction”: “foo equals bar and foo equals baz” becoming “foo equals bar and baz”. The term you might be thinking of is “right node raising”[1], which is when the elements of a conjunction “share” the stuff that follows them, as in “bar equals, and baz equals, foo”. [1]: https://en.wikipedia.org/wiki/Right_node_raising https://en.wikipedia.org/wiki/Right_node_raising
- LambdaComplex 9y agoYes, "right node raising" is exactly what I was looking for. Thank you!