start | find | index | login or register | edit
by earl, 4399 days ago
You're writing "production-grade" code for a large project and encounter the following problem. You have to encode (in C) a decision that somewhat naturally maps to:

(x == 0 && y == 1) ||
(x == 1 && y == 0) ||
(x == 1 && y == 1 && p)

"Naturally" means, if you consider and enumerate all valid possibilities, you'll get the above as result. (x, y are integers >= 0 and p is simply a boolean predicate, the detailed structure of which is of no interest for the remaining discussion.)

Well, after a short timespan of pondering this piece of code, you notice that it is equivalent to the following:

(x | y) == 1 && (x == 0 || y == 0 || p)

Question: which piece do you finally decide to keep?

A few more bits of information: x, y, and p are expressions but are not very expensive to compute; you are also using a compiler that is sufficiently intelligent to avoid redundant calculations of those expressions. You have to comment the chosen piece in any case and phrasing the comment to reflect the structure of the code gives a readable and easy to understand explanation for both implementations.
powered by vanilla
echo earlZstrainYat|tr ZY @. • esa3 • online for 7452 days • c'est un vanilla site