Date: 2009-02-02 07:02 pm (UTC)
concerning why 0 should come before the = and quantity comes after?

That particular one is not style as much as safety. In a lot of languages, the difference between equality tests and assignment is one character ("==" vs. "="). Since most of those languages don't allow expressions to be assigned values, putting the constant on the left will make that kind of error a compilation one, not a runtime one.

The general answer (in the absence as any safety issues) is to strive for the expression to read well. There is a famous web designer who's thesis is "don't make me think" and (as weird as it sounds) it applies in programming, too. The less bandwidth taken up by your mind parsing the programming language, the more cycles that are available to solve problems.

Is there a reason to avoid "if quantity != 1"?

Yeah, you caught me there. :-) I realized after I posted (ain't that always the way?) that in English -1 is read as plural, so you're right, only the 1 quantity is special. In light of that, I would invert the test and have the majority of quantities be plural and 1 be the exception.
This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

June 2025

S M T W T F S
1234567
891011121314
15161718192021
2223 2425262728
2930     

Most Popular Tags