Article 513P CodeSOD: Negative Creativity

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:

256px-Big_Ben_Negative.jpg

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.

release50.png[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! TheDailyWtf?d=yIl2AUoC8zAJ-hHiXJyRtE
External Content
Source RSS or Atom Feed
Feed Location http://syndication.thedailywtf.com/TheDailyWtf
Feed Title The Daily WTF
Feed Link http://thedailywtf.com/
Reply 0 comments