start | find | index | login or register | edit | ||
2009-07-13
by earl, 5609 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) || "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:
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.
|
search 32 active users
backlinks (more) none, yet recent stores (more) recent comments echo earlZstrainYat|tr ZY @. |
|
earl.strain.at • esa3 • online for 8662 days • c'est un vanilla site |