Click here to Skip to main content
15,902,635 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: It's not the most obvious piece of logic. Pin
harold aptroot23-Oct-10 11:04
harold aptroot23-Oct-10 11:04 
GeneralRe: It's not the most obvious piece of logic. Pin
Xiangyang Liu 刘向阳23-Oct-10 5:42
Xiangyang Liu 刘向阳23-Oct-10 5:42 
GeneralRe: It's not the most obvious piece of logic. Pin
Pete O'Hanlon23-Oct-10 10:09
mvePete O'Hanlon23-Oct-10 10:09 
GeneralRe: It's not the most obvious piece of logic. Pin
fjdiewornncalwe24-Oct-10 6:47
professionalfjdiewornncalwe24-Oct-10 6:47 
GeneralRe: It's not the most obvious piece of logic. Pin
BillW3325-Oct-10 7:50
professionalBillW3325-Oct-10 7:50 
GeneralRe: It's not the most obvious piece of logic. Pin
Thomas Vanderhoof26-Oct-10 3:02
professionalThomas Vanderhoof26-Oct-10 3:02 
GeneralRe: It's not the most obvious piece of logic. Pin
James Lonero27-Oct-10 10:51
James Lonero27-Oct-10 10:51 
GeneralRe: It's not the most obvious piece of logic. Pin
supercat925-Oct-10 12:21
supercat925-Oct-10 12:21 
It may be that the person is using a general pattern of testing whether required input conditions are not met by throwing on their inverse. When preconditions are more complicated, it can sometimes be cleaner say something like:
/* Either foo or bar must be true */
if (!(foo || bar))
  throw new InvalidArgumentException("Neither foo nor bar was valid");

Than to say:
/* Either foo or bar must be true */
if (!foo && !bar)
  throw new InvalidArgumentException("Neither foo nor bar was valid");

If one habitually writes pre-checks based upon preconditions, code will probably read better if one consistently uses the same style. If there will be any need to test preconditions using throw-if-not-met logic, it may be best to do so consistently.

Also, btw, if one is going to be pasting code into something like a web-based forum, it may be helpful to write conditions so as to avoid the less-than sign. My usual rewrite of a less-than-zero condition for web posting would typically be "0 > whatever" rather than "!(whatever >= 0)", but some people may prefer the latter style.
GeneralRe: It's not the most obvious piece of logic. PinPopular
normanS25-Oct-10 20:59
normanS25-Oct-10 20:59 
GeneralRe: It's not the most obvious piece of logic. Pin
Super Lloyd25-Oct-10 22:49
Super Lloyd25-Oct-10 22:49 
GeneralRe: It's not the most obvious piece of logic. Pin
Thomas Vanderhoof26-Oct-10 3:07
professionalThomas Vanderhoof26-Oct-10 3:07 
GeneralRe: It's not the most obvious piece of logic. Pin
Super Lloyd26-Oct-10 4:01
Super Lloyd26-Oct-10 4:01 
JokeRe: It's not the most obvious piece of logic. Pin
Jyothikarthik_N26-Dec-10 19:13
Jyothikarthik_N26-Dec-10 19:13 
GeneralRe: It's not the most obvious piece of logic. Pin
Jeff Connelly26-Oct-10 4:57
Jeff Connelly26-Oct-10 4:57 
GeneralRe: It's not the most obvious piece of logic. Pin
KChandos26-Oct-10 6:39
professionalKChandos26-Oct-10 6:39 
GeneralRe: It's not the most obvious piece of logic. Pin
Pete O'Hanlon26-Oct-10 9:43
mvePete O'Hanlon26-Oct-10 9:43 
GeneralRe: It's not the most obvious piece of logic. Pin
Richard Deeming26-Oct-10 7:54
mveRichard Deeming26-Oct-10 7:54 
GeneralRe: It's not the most obvious piece of logic. Pin
Pete O'Hanlon26-Oct-10 9:44
mvePete O'Hanlon26-Oct-10 9:44 
GeneralRe: It's not the most obvious piece of logic. Pin
FrankLaPiana26-Oct-10 8:44
FrankLaPiana26-Oct-10 8:44 
GeneralRe: It's not the most obvious piece of logic. Pin
Keith Barrow26-Oct-10 10:52
professionalKeith Barrow26-Oct-10 10:52 
GeneralRe: It's not the most obvious piece of logic. Pin
Pete O'Hanlon26-Oct-10 11:04
mvePete O'Hanlon26-Oct-10 11:04 
GeneralRe: It's not the most obvious piece of logic. Pin
KP Lee26-Oct-10 13:55
KP Lee26-Oct-10 13:55 
GeneralRe: It's not the most obvious piece of logic. Pin
KP Lee26-Oct-10 11:31
KP Lee26-Oct-10 11:31 
GeneralRe: It's not the most obvious piece of logic. Pin
Dalek Dave26-Oct-10 11:37
professionalDalek Dave26-Oct-10 11:37 
GeneralRe: It's not the most obvious piece of logic. Pin
Stephen Hewitt27-Oct-10 19:02
Stephen Hewitt27-Oct-10 19:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.