(CONSTANT == var) vs. (var == CONSTANT)


I’ve been programming for quite some time now, but until now I never understood why some programmers prefer
CONSTANT == var over var == CONSTANT

It’s to avoid a common C coding mistake of using = instead of ==. If you use the former form, and you inadvertently use = instead of ==, the compiler will catch your mistake because you’d be trying to assign a value to a constant.

I never really needed this convention because I have always been careful with my ==’s. One of the earliest C lessons I’ve learned. Still, it’s helpful to understand why some veterans prefer one form over the other.

  1. No comments yet.
(will not be published)
*