Well, the distinction between functions and operators is blurred in modern languages, especially in C++ where you can overload operators to invoke user-defined functions.
But operator precedences is a real pain in the butt to remember and to be 100% sure it's correct. I adhere to the "don't make me think" principle, I almost always add a lot of unnecessary parenthesis to anything involving shifts and masks since it makes it easier to read and understand without thinking.
The book "Don't Make Me Think: A Common Sense Approach to Web Usability" by Steve Krug is a excellet read even if it is non-electronics and non-code related.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.
No mention that sizeof is not a function and doesn't need the parenthesis except for types?
double arr[100];
int arrsize = sizeof arr;
But to be honest I always tack on a pair of () even if not strictly necessary because then I don't have to think and it looks prettier ;-)
Are you sure? yes | no
Well, the distinction between functions and operators is blurred in modern languages, especially in C++ where you can overload operators to invoke user-defined functions.
Like you I tack on () so that I don't risk being surprised by operator precedence: https://en.cppreference.com/w/c/language/operator_precedence
Probably less forgivable is my habit of using () on return which is definitely not an operator or function. :)
Are you sure? yes | no
return (res);
}
Oh.... That's ugly. ^__^
But operator precedences is a real pain in the butt to remember and to be 100% sure it's correct. I adhere to the "don't make me think" principle, I almost always add a lot of unnecessary parenthesis to anything involving shifts and masks since it makes it easier to read and understand without thinking.
The book "Don't Make Me Think: A Common Sense Approach to Web Usability" by Steve Krug is a excellet read even if it is non-electronics and non-code related.
Are you sure? yes | no