Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

If 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.



You 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?




Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: