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

 
GeneralUseful code comments [modified] Pin
Fred van Lieshout9-May-11 21:23
Fred van Lieshout9-May-11 21:23 
GeneralRe: Useful code comments Pin
Sander Rossel9-May-11 21:41
professionalSander Rossel9-May-11 21:41 
GeneralRe: Useful code comments Pin
Fred van Lieshout9-May-11 23:00
Fred van Lieshout9-May-11 23:00 
JokeRe: Useful code comments Pin
Sander Rossel9-May-11 23:02
professionalSander Rossel9-May-11 23:02 
GeneralRe: Useful code comments Pin
GenJerDan10-May-11 3:49
GenJerDan10-May-11 3:49 
GeneralRe: Useful code comments Pin
OriginalGriff10-May-11 4:52
mveOriginalGriff10-May-11 4:52 
GeneralRe: Useful code comments Pin
BillW3312-May-11 4:21
professionalBillW3312-May-11 4:21 
GeneralRe: Useful code comments [modified] Pin
R. Erasmus10-May-11 22:39
R. Erasmus10-May-11 22:39 
If I were to log a bug against it I'd say that "magic numbers were used".
Rather create a constant. Avoid magic numbers at all cost.

/*--[ Private Literals ]-------------------------------*/
#define MAX_STR_LEN 10

/*--[ Public Functions ]-------------------------------*/

/* 
  This is the main entry point of the software.
*/
public int main()
{
  if (CheckStringLength)
  {
    // perform operations
  }
  else
  {
    // do nothing
  }

  return 0;
}

/*--[ Private Functions ]-------------------------------*/

/* 
  This function validates string length.
*/
private boolean CheckStringLength(char* str)
{
  boolean result = false;
  unsigned int len = 0;
  while(str++ != '\0')
  {
    len++;
  }

  /* validate string lenght */
  if (len <= MAX_STR_LEN)
  {
    result = true;
  }
  else
  {
    result = false;
  }

  return result;
}


In actual fact it would of probebly been better to define the constant in a header file.
This way when the string length changes the actual source file doesn't change but just
the value of the constant defined in the header file and thus the testing of the source
file is not required again.
"Program testing can be used to show the presence of bugs, but never to show their absence."

<< please vote!! >>
modified on Wednesday, May 11, 2011 6:52 AM

GeneralRe: Useful code comments Pin
Fred van Lieshout10-May-11 23:13
Fred van Lieshout10-May-11 23:13 
GeneralRe: Useful code comments Pin
Sterling Camden / independent consultant13-May-11 7:01
Sterling Camden / independent consultant13-May-11 7:01 
GeneralThe "best" way ever to compare two dates... Pin
mr.bart.simpson9-May-11 1:28
professionalmr.bart.simpson9-May-11 1:28 
GeneralRe: The "best" way ever to compare two dates... Pin
BillW3312-May-11 4:18
professionalBillW3312-May-11 4:18 
GeneralWhy oh why??? Pin
emartinho5-May-11 8:48
emartinho5-May-11 8:48 
GeneralRe: Why oh why??? Pin
RobCroll6-May-11 3:24
RobCroll6-May-11 3:24 
GeneralRe: Why oh why??? Pin
Marc A. Brown6-May-11 4:50
Marc A. Brown6-May-11 4:50 
GeneralRe: Why oh why??? Pin
emartinho6-May-11 5:56
emartinho6-May-11 5:56 
GeneralRe: Why oh why??? PinPopular
Luc Pattyn6-May-11 4:04
sitebuilderLuc Pattyn6-May-11 4:04 
GeneralRe: Why oh why??? Pin
Marc A. Brown6-May-11 4:50
Marc A. Brown6-May-11 4:50 
GeneralRe: Why oh why??? Pin
emartinho6-May-11 5:53
emartinho6-May-11 5:53 
GeneralRe: Why oh why??? Pin
Blake Miller6-May-11 7:17
Blake Miller6-May-11 7:17 
GeneralRe: Why oh why??? Pin
Pong D. Panda6-May-11 22:06
Pong D. Panda6-May-11 22:06 
GeneralThe mysteriously deleted file PinPopular
Joe Woodbury4-May-11 7:22
professionalJoe Woodbury4-May-11 7:22 
GeneralBrilliant Logic Pin
Roman_wolf3-May-11 21:59
Roman_wolf3-May-11 21:59 
GeneralRe: Brilliant Logic PinPopular
musefan4-May-11 3:00
musefan4-May-11 3:00 
GeneralRe: Brilliant Logic Pin
BillW334-May-11 3:05
professionalBillW334-May-11 3:05 

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.