Click here to Skip to main content
15,886,873 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: Do you not understand booleans? Pin
YvesDaoust12-Dec-11 4:14
YvesDaoust12-Dec-11 4:14 
GeneralRe: Do you not understand booleans? Pin
BloodyBaron1-Jan-12 3:25
BloodyBaron1-Jan-12 3:25 
GeneralRe: Do you not understand booleans? Pin
YvesDaoust1-Jan-12 22:57
YvesDaoust1-Jan-12 22:57 
GeneralRe: Do you not understand booleans? Pin
Imperion12-Dec-11 4:44
Imperion12-Dec-11 4:44 
GeneralRe: Do you not understand booleans? Pin
Stefan_Lang12-Dec-11 6:02
Stefan_Lang12-Dec-11 6:02 
GeneralRe: Do you not understand booleans? Pin
Imperion12-Dec-11 6:36
Imperion12-Dec-11 6:36 
GeneralRe: Do you not understand booleans? Pin
JBoyer1112-Dec-11 4:45
JBoyer1112-Dec-11 4:45 
GeneralRe: Do you not understand booleans? Pin
Stefan_Lang12-Dec-11 6:00
Stefan_Lang12-Dec-11 6:00 
Let's see...

The first example I don't like - not for the if statement, but for the premature returns! Personally, I'd make it a one-liner, but I don't consider it all that horrible apart from the returns.

The second ... well you could argue it's slightly more readable for inexperienced programmers, but if that is your purpose then you should write an if/else statement, not use ?:.

The next is a double horror for comparing to boolean constants and unnecessary nesting, but I'd forgive the nesting for the off-chance of later maintenance introducing additional statements that depend on only the first condition.

The last ... I suppose if you need to be able to run your code through really old C compilers that don't have their own built-in definitions of bool, true and false, then it makes sense not to assign one boolean variable blindly to another, but instead make an if/else statement to catch the case where the argument is neither true nor false. But even then, ==true is horrible.

So, in short, all of the examples are indeed bad style, IMHO, but I agree with the others that no harm is done, except maybe a minor hit in maintenance effort for posting it in the Hall of Shame. Wink | ;) None of this will cause inefficiency either, since compilers are smart enough to produce efficient code even from that kind of code.
GeneralRe: Do you not understand booleans? Pin
patbob12-Dec-11 6:13
patbob12-Dec-11 6:13 
GeneralRe: Do you not understand booleans? Pin
YvesDaoust1-Jan-12 23:42
YvesDaoust1-Jan-12 23:42 
GeneralRe: Do you not understand booleans? Pin
patbob3-Jan-12 6:39
patbob3-Jan-12 6:39 
GeneralRe: Do you not understand booleans? Pin
YvesDaoust3-Jan-12 23:48
YvesDaoust3-Jan-12 23:48 
JokeRe: Do you not understand booleans? Pin
Rick Shaub12-Dec-11 7:27
Rick Shaub12-Dec-11 7:27 
GeneralRe: Do you not understand booleans? Pin
Stefan_Lang12-Dec-11 21:57
Stefan_Lang12-Dec-11 21:57 
GeneralRe: Do you not understand booleans? Pin
rcampbell1212-Dec-11 10:51
rcampbell1212-Dec-11 10:51 
GeneralRe: Do you not understand booleans? Pin
Nunnenkamp13-Dec-11 6:34
Nunnenkamp13-Dec-11 6:34 
GeneralRe: Do you not understand booleans? Pin
fjdiewornncalwe13-Dec-11 7:08
professionalfjdiewornncalwe13-Dec-11 7:08 
GeneralRe: Do you not understand booleans? Pin
YvesDaoust1-Jan-12 23:50
YvesDaoust1-Jan-12 23:50 
GeneralRe: Do you not understand booleans? Pin
KP Lee13-Dec-11 19:19
KP Lee13-Dec-11 19:19 
GeneralRe: Do you not understand booleans? Pin
Clive D. Pottinger15-Dec-11 17:09
Clive D. Pottinger15-Dec-11 17:09 
GeneralRe: Do you not understand booleans? Pin
John Hunley19-Dec-11 6:47
John Hunley19-Dec-11 6:47 
GeneralRe: Do you not understand booleans? Pin
YvesDaoust2-Jan-12 0:10
YvesDaoust2-Jan-12 0:10 
GeneralRe: Do you not understand booleans? Pin
Jeroen De Dauw25-Dec-11 11:24
Jeroen De Dauw25-Dec-11 11:24 
GeneralRe: Do you not understand booleans? Pin
ChunkyStool3-Jan-12 12:25
ChunkyStool3-Jan-12 12:25 
GeneralI just found... Pin
TorstenH.4-Dec-11 23:38
TorstenH.4-Dec-11 23:38 

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.