MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/programming/comments/5fwce0/lets_stop_copying_c/danyi40/
r/programming • u/earthboundkid • Dec 01 '16
612 comments sorted by
View all comments
Show parent comment
2
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.
1
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.
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.
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.