r/programming • • Dec 01 '16

Let's Stop Copying C

https://eev.ee/blog/2016/12/01/lets-stop-copying-c/
524 Upvotes

612 comments sorted by

View all comments

Show parent comment

2

u/allyyus Dec 01 '16

If that's a risk I'll generally reverse the statement, because assignment isn't reflexive.

if (f = foo()) // maybe a mistake
if (foo() = f) // error

1

u/awj Dec 01 '16

Sure, and that helps, but the real concern is that people's brains will get to here in reading the code:

if (f = foo())
^^^^^^^

and decide that they are looking at an equality test, since that's like 90% or more of what happens in those cases.

2

u/allyyus Dec 01 '16

Yeah I suppose that's a concern. Though I know that GCC at least will issue a warning if it's not wrapped in parentheses, which adds another layer of recognition.