When the CEO becomes a developer I
-
A company hired me for cleaning up the PHP-code the CEO created. The whole code reads like a how-not-to of programming, so I decided to post some of the gems here. This is the first one (I preserved all the formatting):
MyCart::IsContentvalid()
checks items in the cart against a database. Each call does 3 queries (per item!) of tables with around 500.000 entries. Note also the clever use of quotation marks.if(MyCart::IsContentvalid()==1) { Helper::Redirect("confirmation.php"); } if(MyCart::IsContentvalid()==2) { $this->setErrorMsg("$curlang\[error\_msg1\]"); } if(MyCart::IsContentvalid()==-12) { $this->setErrorMsg("These items can not be sold."); } if(MyCart::IsContentvalid()==15) { $this->setErrorMsg("Your account doesn't allow you to buy these items."); } else { //Helper::Redirect("confirmation.php"); $this->setErrorMsg("$lang\[error\_msg2\]"); }
Oh, and the use of
else
is only for advanced programmers:if ($result == 1)
{
// do something here
}
if ($result != 1)
{
// do something else here
}More will come soon!
-
A company hired me for cleaning up the PHP-code the CEO created. The whole code reads like a how-not-to of programming, so I decided to post some of the gems here. This is the first one (I preserved all the formatting):
MyCart::IsContentvalid()
checks items in the cart against a database. Each call does 3 queries (per item!) of tables with around 500.000 entries. Note also the clever use of quotation marks.if(MyCart::IsContentvalid()==1) { Helper::Redirect("confirmation.php"); } if(MyCart::IsContentvalid()==2) { $this->setErrorMsg("$curlang\[error\_msg1\]"); } if(MyCart::IsContentvalid()==-12) { $this->setErrorMsg("These items can not be sold."); } if(MyCart::IsContentvalid()==15) { $this->setErrorMsg("Your account doesn't allow you to buy these items."); } else { //Helper::Redirect("confirmation.php"); $this->setErrorMsg("$lang\[error\_msg2\]"); }
Oh, and the use of
else
is only for advanced programmers:if ($result == 1)
{
// do something here
}
if ($result != 1)
{
// do something else here
}More will come soon!