|
-
October 9th, 2009, 09:57 AM
#16
Re: C - <= and >= Problems
 Originally Posted by JohnW@Wessex
A simple example
A && B || C
You could assume that the coder knows the operator precedence and it does what he intended.
If he were to type A && (B || C) then it doesn't matter whether the coder remembers && or || has the higher precedence, it will work as intended.
Now imagine a much longer and more complicated logic test.
I stick to this principle because it alleviates having to debug silly mistakes and lets me concentrate on the bigger issues.
If parenthesis are superfluous, then what about spaces and carriage returns?
Code:
#include<iostream>
#include<string>
int main(){std::string name;std::cout<<"Name?";std::cin>>name;std::cout<<"Hello "<<name;}
It's not about whether things are superfluous or not, it's about readability and conciseness of meaning;
Spaces and carriage returns are for readability. Parenthesis are there for grouping to change the natural order of evaluation. Spaces don't change logic. Parenthesis do, so when they're there, it's assumed that they're there to affect logic, at least by me. Maybe they make it more readable to you but to me they're there to change the normal order of evaluation and it seems strange to add them when they do nothing.
In the code in this case it's a simple logical and. There's nothing confusing or ambiguous about it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|