CodeSOD: Negative Creativity
by Jane Bailey from The Daily WTF on (#513P)
Pop quiz: how do you ensure that a number is negative? You could do something like:
if (count > 0) {count = count * -1}
Or you could use a ternary:
count = count > 0 ? count * -1 : count;
Or, if you're feeling fancy, use absolute value, like
count = Math.Abs(count) * -1;
If you're Justin's coworker, however, that's not good enough. No, what you REALLY want to do is coerce to a string, prepend a negative sign, then remove any double-negatives to make a positive again:
if (count > 0 || count
Now that's fancy.
[Advertisement] Release!is a light card game about software and the people who make it. Play with 2-5 people, or up to 10 with two copies - only $9.95 shipped!