Click here to Skip to main content
15,912,578 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: Another Horror Pin
VentsyV2-Oct-08 8:37
VentsyV2-Oct-08 8:37 
JokeRe: Another Horror Pin
cpkilekofp2-Oct-08 9:54
cpkilekofp2-Oct-08 9:54 
GeneralRe: Another Horror PinPopular
Pete O'Hanlon29-Sep-08 8:14
mvePete O'Hanlon29-Sep-08 8:14 
GeneralRe: Another Horror Pin
dojohansen1-Oct-08 4:32
dojohansen1-Oct-08 4:32 
GeneralRe: Another Horror Pin
dojohansen1-Oct-08 5:46
dojohansen1-Oct-08 5:46 
GeneralRe: Another Horror Pin
Sauce!1-Oct-08 23:01
Sauce!1-Oct-08 23:01 
JokeRe: Another Horror Pin
ChrisKiki6-Oct-08 0:27
ChrisKiki6-Oct-08 0:27 
GeneralThis is just for the laugh of it. PinPopular
adamsappel22-Sep-08 2:24
adamsappel22-Sep-08 2:24 
Hi. Background: Co-Worker, (Female <- not biased, just stating the fact), Qualification: Architect...
(btw, this is all C# VS2008 code, I swear)

Ok, one for the count:

public static bool NameExists (string name)
{
   bool exists = false;
   int i = 0;
   while ((i < someListContainingNames.Count) && (exists == false))
   {
      if (someListContainingNames[i] == filename)
      {
         exists = true;
      }
      i++;
   }
   return exists;
}


Please see if you can read this... (Original code kept):

else if (   ((isEXEDLL == true) || (isEXEConfig == true))
         && ((staysTheSameEXEDLL == false) || (EXEDLLPathExistsSoCanProcess == true))
         )
{
   if (  ((isEXEDLL == true) || (isEXEConfig == true))
      && (staysTheSameEXEDLL == false)
      )
   {
      if (canCopy.DoCopy == true)
      {


Spot the redundency (Regex's left out):

string str = "";
string str2 = "";
Regex regex1 = new Regex(regex1String, RegexOptions.IgnoreCase);
Regex regex2 = new Regex(regex2String, RegexOptions.IgnoreCase);
Regex regex3 = new Regex(regex3String, RegexOptions.IgnoreCase);
Regex regex4 = new Regex(regex4String, RegexOptions.IgnoreCase);

if (regex1.IsMatch(filename))
{
   str = regex1.Match(filename).Groups["code"].Value.ToUpper();
   str2 = regex1.Match(filename).Groups["type"].Value.ToUpper();
}
else if (regex2.IsMatch(filename))
{
   str = regex2.Match(filename).Groups["code"].Value.ToUpper();
   str2 = regex2.Match(filename).Groups["type"].Value.ToUpper();
}
else if (regex3.IsMatch(filename))
{
   str = regex3.Match(filename).Groups["code"].Value.ToUpper();
   str2 = regex3.Match(filename).Groups["type"].Value.ToUpper();
}
else if (regex4.IsMatch(filename))
{
   str = regex4.Match(filename).Groups["code"].Value.ToUpper();
   str2 = regex4.Match(filename).Groups["type"].Value.ToUpper();
}
else
{
   str = "";
   str2 = "";
}

if (  (regex1.IsMatch(filename))
   || (regex2.IsMatch(filename))
   || (regex3.IsMatch(filename))
   || (regex4.IsMatch(filename))
   )
{


Didn't get that one? Try this one:

if (dr.GetValue(dr.GetOrdinal("Copy")).ToString().Trim() == "1")
   copyChecked = true;
else
   copyChecked = false;


Ok, now I'm not pedantic, this I can promise you, but when you come across something like this little gem... (Only method name and class type changed...)

public static bool MethodName(ObjectWithBoolean objectThatHasBool)
{
   if (objectThatHasBool.booleanValue)
   {
      return false;
   }
   else
   {
      return true;
   }
}


Last, but DEFINITELY not the least, here's a little sql query that my "collegue" wrote. See if you can spot the query:

StringBuilder queryString = new StringBuilder();
//this is the query that updates the actual data
queryString.Append("IF EXISTS ");
queryString.Append("(SELECT ID ");
queryString.Append("FROM ");
queryString.Append("Table1 ");
queryString.Append("WHERE ID = ");
queryString.Append(id);
queryString.Append(") ");
queryString.Append("BEGIN ");
queryString.Append("UPDATE ");
queryString.Append("Table1 SET ");
queryString.Append("ComlumnValue1 = ");
queryString.Append("'");
queryString.Append(Value1);
queryString.Append("' ");
queryString.Append(", ComlumnValue2 = ");
queryString.Append(Value2);
queryString.Append(", ComlumnValue3 = ");
queryString.Append(Value3);
queryString.Append(" WHERE ID = ");
queryString.Append("'");
queryString.Append(id);
queryString.Append("' ");
queryString.Append("AND ");
queryString.Append("(ISNULL(ComlumnValue1,0) <> ");
queryString.Append("'");
queryString.Append(Value1);
queryString.Append("' ");
queryString.Append(" OR ");
queryString.Append("ISNULL(ComlumnValue2,0) <> ");
queryString.Append(Value2);
queryString.Append(" OR ");
queryString.Append("ISNULL(ComlumnValue3,0) <> ");
queryString.Append(Value3);
queryString.Append(") ");
queryString.Append(" END ");
queryString.Append("ELSE BEGIN declare @ID int ");
queryString.Append("exec ssl_GetTable1CallSeq 1, ");
queryString.Append("@ID OUTPUT ");
queryString.Append("IF ");
queryString.Append("NOT EXISTS(SELECT * FROM Table1 WHERE ID = ");
queryString.Append(id);
queryString.Append(") ");
queryString.Append("INSERT ");
queryString.Append("INTO Table1 (ID, Name, ");
queryString.Append("ComlumnValue1, ");
queryString.Append("ComlumnValue2, ");
queryString.Append("ComlumnValue3) ");
queryString.Append("VALUES ");
queryString.Append("(@ID, ");
queryString.Append("'");
queryString.Append(name);
queryString.Append("', ");
queryString.Append("'");
queryString.Append(Value1);
queryString.Append("', ");
queryString.Append(Value2);
queryString.Append(", ");
queryString.Append(Value3);
queryString.Append(" ) END ");

command.CommandText = queryString.ToString();


Thanks for listening to my little rant. Any comments very welcome, Smile | :)
GeneralRe: This is just for the laugh of it. PinPopular
CPallini22-Sep-08 3:06
mveCPallini22-Sep-08 3:06 
GeneralRe: This is just for the laugh of it. PinPopular
Dan Neely22-Sep-08 3:48
Dan Neely22-Sep-08 3:48 
GeneralRe: This is just for the laugh of it. Pin
PIEBALDconsult22-Sep-08 17:32
mvePIEBALDconsult22-Sep-08 17:32 
GeneralRe: This is just for the laugh of it. Pin
adamsappel22-Sep-08 21:58
adamsappel22-Sep-08 21:58 
GeneralRe: This is just for the laugh of it. Pin
jamie55022-Sep-08 22:08
jamie55022-Sep-08 22:08 
AnswerRe: This is just for the laugh of it. PinPopular
Nagy Vilmos22-Sep-08 22:42
professionalNagy Vilmos22-Sep-08 22:42 
GeneralRe: This is just for the laugh of it. Pin
Baconbutty23-Sep-08 4:40
Baconbutty23-Sep-08 4:40 
GeneralRe: This is just for the laugh of it. Pin
adamsappel25-Sep-08 0:37
adamsappel25-Sep-08 0:37 
GeneralRe: This is just for the laugh of it. Pin
cpkilekofp25-Sep-08 3:14
cpkilekofp25-Sep-08 3:14 
GeneralRe: This is just for the laugh of it. Pin
Pete O'Hanlon25-Sep-08 4:29
mvePete O'Hanlon25-Sep-08 4:29 
JokeRe: This is just for the laugh of it. Pin
Paul Conrad25-Sep-08 6:26
professionalPaul Conrad25-Sep-08 6:26 
GeneralRe: This is just for the laugh of it. Pin
cpkilekofp25-Sep-08 6:39
cpkilekofp25-Sep-08 6:39 
GeneralRe: This is just for the laugh of it. PinPopular
Pete O'Hanlon25-Sep-08 4:47
mvePete O'Hanlon25-Sep-08 4:47 
GeneralRe: This is just for the laugh of it. Pin
Paul Conrad25-Sep-08 6:28
professionalPaul Conrad25-Sep-08 6:28 
GeneralRe: This is just for the laugh of it. Pin
adamsappel25-Sep-08 23:42
adamsappel25-Sep-08 23:42 
GeneralRe: This is just for the laugh of it. Pin
Dan Neely26-Sep-08 2:12
Dan Neely26-Sep-08 2:12 
GeneralRe: This is just for the laugh of it. Pin
Malli_S23-Sep-08 4:59
Malli_S23-Sep-08 4:59 

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.