Some people find conditions with the constant on the left, like `(0 == foo)`, jarring and difficult to read. Other people apparently aren't bothered by them. In my experience, neither group of people will be convinced by the other side's arguments.
Some people find conditions with the constant on the left, like `(0 == foo)`, jarring and difficult to read. Other people apparently aren't bothered by them. In my experience, neither group of people will be convinced by the other side's arguments.
As for it being jarring, well that's sometimes a good thing. Narrow city roads with heavy pedestrian traffic can make an automobile driver feel anxious and convinced the road unsafe. But making the driver uncomfortable is precisely what makes the road actually objectively safer.
If you want a reader to slow down and appreciate a critical statement, then swapping the operands can sometimes accomplish that in a way that comments may not.
I'm nearly ambivalent on them: I'm no programmer. On the one hand it looks like relying on behaviour that is correct now but may not be so in the future. On the other it is a little extra safety. It looks horrid. Its a nice mini hack.
Nahh: Too specific to one small potential source of error. Rely on this sort of nonsense and before you know it you'll be invoking magic. Use a decent IDE that looks out for it if you need reminding about this class of bug.
> Use a decent IDE that looks out for it if you need reminding about this class of bug.
And when your next environment/plugin/employer's setup changes or doesn't offer this warning? Or the day that getting your critical system back up ASAP leaves you no choice but to SSH in from your phone and edit your source in Nano?
Learning and practicing defensive programming as a professional programmer is like defensive driving for a taxi driver, or survival skills for a long-distance hiker. It's a part of what someone who considers themselves a serious professional should maintain.
Relying on a 'decent IDE' to manage your code quality for you is an excellent way to blunt your skills. I'm not saying we should all throw IDEs away or turn off their warnings, but to rely on them is an awful substitute for maintaining good practice. Granted, crossing every t and dotting every i is much, much harder in C than most other languages, but every compiler warning you have to hunt down and fix is another little slice of your day shaved off and gone.