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
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 
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 
Personally, I don't promote the C rule that implicitly turns an expression to boolean based on zeroness, whatever the type. Because even though perfectly legal it looks like a quick & dirty shorthand to spare typing a comparison; and it can overload an identifier with two meanings, that of the numerical value (or address) and that of a condition, as if the variable had two data types.

What would you think of this (fiddled) snippet:
C++
int NoRetries; // Number of sending retries
NoRetries= SendMessage();
if (NoRetries)
{
  // Investigate
}


as opposed to

C++
if (NoRetries > 0)
{
  // Investigate
}


C was lacking a boolean type in the old days, in my opinion a design flaw. That made the aforementioned rule perfectly relevant. I prefer making the booleans explicit and highlighted.

In a moderatly pedantic style, this would give us

C++
bool Retried= NoRetries > 0;
if (Retried)
{
  // Investigate
}

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 
GeneralRe: I just found... Pin
CDP18025-Dec-11 2:06
CDP18025-Dec-11 2:06 
GeneralRe: I just found... Pin
Nagy Vilmos5-Dec-11 4:29
professionalNagy Vilmos5-Dec-11 4:29 

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.