tags:

views:

229

answers:

8

Today, I was reviewing some code a coworker had written recently. The following statement seemed to jump off the screen at me.

string defaultValue = (1000).ToString();

And this has prompted me to ask the question...

What simple problem have you seen addressed in an unnecessarily complicated manner?

+11  A: 

You can look at the archive at TheDailyWTF. Many examples there.

Ólafur Waage
+1  A: 

Recipe 576766: Hexadecimal Conversion Tool.

Stephan202
+1  A: 

Just saw one today that made me laugh. It's clever in a lot of ways, but not in the one that counts.

<?php
function isNumber($num) {
  $isNum = true;
  for($i=0; $i < strlen($num); $i++) {
    $isNum &= preg_match('/^(0|1|2|3|4|5|6|7|8|9)$/', $num{$i});
  }
  return (bool) $isNum;
}
?>

This is what I get for suggesting regex. Could have just used is_numeric($num) I guess...

psayre23
+6  A: 

Enterprise Fizzbuzz!

The (sole) issue in the tracker is also excellent: http://code.google.com/p/fizzbuzz/issues/detail?id=1

Steve Jessop
A: 
FILE *f;
char mode[2];

mode[0] = 'r';
mode[1] = '\0';

f = fopen( "filename", mode );
Martlark
+1  A: 

This one is my personal favorite. I prefer the constant, but it's more typing

if ( someString == "" )          // Just seems wrong
{ //... magic happens here }

if ( someString == String.Empty) // Seems better but is more complicated
{ //... magic also happens here too }

We all know we should use constants, but when is having simple things as constants too much?

Chris
+3  A: 

Loop trough a collection to load a combo box, insted of using the Databinding feature.

Romias
+2  A: 

There's the classic

if (x > 3)
{
return true;
}
else
{
return false;
}

Of course, if you just want obfuscation, there's always the International Obfuscated C Code Contest.

David Thornley

related questions