3 ms·
This 'reason' is as old as C, and it's always seemed to me like tying bells to your shoelaces because it would be bad if you forgot to tie them and tripped. I.e
by psyc 10y ago
This 'reason' is as old as C, and it's always seemed to me like tying bells to your shoelaces because it would be bad if you forgot to tie them and tripped. I.e. the 'solution' is orthogonal to the problem. If you can train yourself to put the constant first, you can train yourself to use the right operator.
And you can test your code.
- onion2k 10y agoIf you can train yourself to put the constant first, you can train yourself to use the right operator. Ideally, of course. But pragmatically mistakes happen. The point is that there's no cost - so why not use an explicit order and the right operator? And you can test your code. A lot of developers don't, or they only test for simple success cases that wouldn't catch this class of bug. It's scary.
- mattkrause 10y agoYou also have a tireless automated assistant who can check for this: the compiler. Clang warns about this by default: warning: using the result of an assignment as a condition without parentheses. note: place parentheses around the assignment to silence this warning. note: use '==' to turn this assignment into an equality comparison. " gcc gives you similar warnings with -Wall or -Wparentheses: warning: suggest parentheses around assignment used as truth value [-Wparentheses] Why not stick with the more natural phrasing and let the machine handle the tedious work?
- crpatino 10y ago> If you can train yourself to put the constant first, you can train yourself to use the right operator. Right... that's assuming you work solo. In that case, you might as well be using some higher level language and sidestep the whole issue. Most C programmers out there work in teams, in long lived projects... that means teams with rotation of personnel. This is a fuckup waiting to happen. I get you guys do not like axes, and it is really Ok. But forgive me if I am skeptical of your axe redesigns until the day you actually go out and do a full hour of wood chopping with that fancy bastard sword of yours.
- userbinator 10y agoThe argument applies just as well to each member of a team.
- crpatino 10y agoThe argument applies just as well to each member of society. Imagine the savings in law enforcement if every one of us just followed the rules all the time!!!