PDA

View Full Version : Coding Horrors


DarkLord
21st February 2009, 11:45 AM
When I was approached by a colleague for an estimate on some PHP work, I insisted that i'll need to see some of the code first. The only background I had on the project was that it was a PHP site with a MySQL backend, and a pretty sizable user base.

When I received the code, the first thing that I noticed was an unreasonably large file called namelib.php. It was apparently intended to clean up users' first names...


<?
$name = $_GET['name'];
switch($name)
{
case "aafke":
echo "Aafke";
break;
case "aaron":
echo "Aaron";
break;
case "abbie":
echo "Abbie";
break;
case "abby":
echo "Abby";
break;
case "abdel":
echo "Abdel";
break;
case "abe":
echo "Abe";
break;
case "abeltje":
echo "Abeltje";
break;

/* Snip */

case "zora":
echo "Zora";
break;
case "zorah":
echo "Zorah";
break;
case "zuzana":
echo "Zuzana";
break;
case "zuzanna":
echo "Zuzanna";
break;
case "zuzanny":
echo "Zuzanny";
break;
default:
echo $name;
// Name not in the database yet, lowercase is better than nothing
}
?>


I couldn't help but LMAO and replaced thousands of lines of generated code with one easy line:


echo ucfirst($_GET['name']);

Yeda Anna
21st February 2009, 12:19 PM
Some people cannot code for long ... hence they take shortcuts :rolleyes:

They suffer from premature ejaculation :tongue:

Admin
4th January 2010, 07:21 PM
Today I encountered this piece of code in our Application and i was like WTF..This has been developed by our self proclaimed .Net Expert :D

This method is supposed to return true if passed string is a number. However, the developer has used interesting logic :D
If lower case and upper case of the string are equal then it is a number :w00t:


public static bool isNumber(string strToCompare)
{
try
{
if (String.IsNullOrEmpty(strToCompare) == false && strToCompare.ToLower() == strToCompare.ToUpper())
return true;
else
return false;
}
catch (Exception ex)
{

}
return false;
}
}

Mastikhor
4th January 2010, 08:28 PM
Today I encountered this piece of code in our Application and i was like WTF..This has been developed by our self proclaimed .Net Expert :D

This method is supposed to return true if passed string is a number. However, the developer has used interesting logic :D
If lower case and upper case of the string are equal then it is a number :w00t:


:adore: :adore:

GodFather
4th January 2010, 09:17 PM
Today I encountered this piece of code in our Application and i was like WTF..This has been developed by our self proclaimed .Net Expert :D

This method is supposed to return true if passed string is a number. However, the developer has used interesting logic :D
If lower case and upper case of the string are equal then it is a number :w00t:


public static bool isNumber(string strToCompare)
{
try
{
if (String.IsNullOrEmpty(strToCompare) == false && strToCompare.ToLower() == strToCompare.ToUpper())
return true;
else
return false;
}
catch (Exception ex)
{

}
return false;
}
}


You know, I too have one self proclaimed .NET expert here. Who hates Javascript and one day I told him, do you know how the .NET framework operates. How the postback happens....