Click here to Skip to main content
15,889,877 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.

 
GeneralLogical genius! Pin
Simone Serponi19-May-10 3:01
Simone Serponi19-May-10 3:01 
GeneralRe: Logical genius! Pin
Dr.Walt Fair, PE19-May-10 5:19
professionalDr.Walt Fair, PE19-May-10 5:19 
GeneralRe: Logical genius! Pin
Chris Boden19-May-10 5:40
Chris Boden19-May-10 5:40 
GeneralRe: Logical genius! Pin
supercat919-May-10 6:40
supercat919-May-10 6:40 
GeneralRe: Logical genius! Pin
Richard MacCutchan19-May-10 21:44
mveRichard MacCutchan19-May-10 21:44 
GeneralRe: Logical genius! Pin
supercat920-May-10 5:01
supercat920-May-10 5:01 
GeneralRe: Logical genius! Pin
Richard MacCutchan20-May-10 6:54
mveRichard MacCutchan20-May-10 6:54 
GeneralRe: Logical genius! Pin
Simone Serponi21-May-10 4:08
Simone Serponi21-May-10 4:08 
Yes, as you said, the code snippet I've posted is not complete (As I told I've not posted the actual code) However the coder was NOT minding to use the 'if' form to ensure return 'true' or 'false' independently from what value is in m_bUsed (moreover this is guarantee to be 'ture' or 'false' only by the code that modify it).

A more rational implementation using the 'if; form could be the following:

bool IsUsed ( int iHandle )
{
   if ( iHandle < MAX_CFG )
      return ( true == g_vConfigurations[iHandle ].m_bUsed );
   else // iHandle >= MAX_CFG
      return false;
}


or (in a more 'compact' form someone can like):

bool IsUsed ( int iHandle )
{
   retrun ( iHandle < MAX_CFG )? ( true == g_vConfigurations[iHandle ].m_bUsed ) : false;
}



Someone can complain about the logic of returning false when parameter is out of range instead of an exception but we can use them (that is a portion of code that recently ported to C++ from C using an "incremental" approach) and stating that "you cannot be using something you don't have" is not so wrong Poke tongue | ;-P
Bye By(t)e Wink | ;-)

JokeRe: Logical genius! Pin
Stanciu Vlad20-May-10 6:08
Stanciu Vlad20-May-10 6:08 
GeneralRe: Logical genius! Pin
scotchfaster20-May-10 7:09
scotchfaster20-May-10 7:09 
GeneralRe: Logical genius! Pin
Simone Serponi21-May-10 4:15
Simone Serponi21-May-10 4:15 
GeneralRe: Logical genius! Pin
cgh197714-Jul-10 6:45
cgh197714-Jul-10 6:45 
GeneralWrong on so many levels Pin
ARopo18-May-10 5:33
ARopo18-May-10 5:33 
GeneralRe: Wrong on so many levels Pin
Chris Boden18-May-10 6:41
Chris Boden18-May-10 6:41 
GeneralRe: Wrong on so many levels Pin
PIEBALDconsult18-May-10 6:56
mvePIEBALDconsult18-May-10 6:56 
GeneralRe: Wrong on so many levels Pin
ARopo18-May-10 21:47
ARopo18-May-10 21:47 
GeneralRe: Wrong on so many levels Pin
David Skelly18-May-10 22:42
David Skelly18-May-10 22:42 
GeneralRe: Wrong on so many levels Pin
ARopo18-May-10 23:47
ARopo18-May-10 23:47 
GeneralRe: Wrong on so many levels Pin
Luc Pattyn19-May-10 2:24
sitebuilderLuc Pattyn19-May-10 2:24 
GeneralRe: Wrong on so many levels Pin
elchupathingy19-May-10 9:53
elchupathingy19-May-10 9:53 
GeneralWhen is a double a string Pin
Not Active13-May-10 4:02
mentorNot Active13-May-10 4:02 
AnswerRe: When is a double a string Pin
Chris Meech13-May-10 4:24
Chris Meech13-May-10 4:24 
GeneralRe: When is a double a string [modified] Pin
Luc Pattyn13-May-10 4:27
sitebuilderLuc Pattyn13-May-10 4:27 
GeneralRe: When is a double a string Pin
Not Active13-May-10 4:38
mentorNot Active13-May-10 4:38 
GeneralRe: When is a double a string Pin
PIEBALDconsult13-May-10 4:44
mvePIEBALDconsult13-May-10 4:44 

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.