Archive for June, 2007|Monthly archive page
Smells to refactoring
Although “smells to Refactoring” is hosted on java.net, the suggested practices within this document are to be applied with any Object Oriented Programming (PHP, Java, Ruby, .Net, …). Every programmer must read it.
Long method is probably one of the most common code smell. Below a list of the troubles a 200 lines method can create :
- it is hard to understand and hard to maintain. Mostly when the only comment can be found at the 130th line and looks like : “POST section”. Thank you very much.
- it is so specific, it is totally impossible to use it in another context. Furthermore, it quickly becomes a copy/paste repository as some code blocks are closed to be generic snippets.
- It is probably doing too much things. This statement becomes obvious as soon as you need to modify some behavior.
- it is an open door to security issues. For two reasons: first, a large piece of code often comes with a high complexity, which is suitable for hard to find vulnerabilities. Then, it is easy to write a clean and secured method with only 15-20 lines, although the same care cannot be applied to a 200 lines method.
This kind of mistake can be easily avoided with a good conception prior to the coding process. Read the entire document, and you will probably conclude by yourself that most of the listed code smells are the aftermaths of a poor design.
Pear::DB is dead. Long live PDO!
Pear::DB is deprecated in favor of Pear::MDB2. I guess this is a good thing because MDB2 is faster, smaller and provides more features. I only guess because I am not a pear user,I do not like Pear as its installation is really weird and the documentation is sometimes insufficient.
By now, two database abstractions are still active in the PHP community : PDO & Pear::MDB2. I recommend PDO If you are writing your application using PHP5 and/or you want your application to be really fast (PDO is a PHP inner class). Pear::MDB2 can be a good thing for PHP4 applications or if you need a high-level of database abstraction in your application.
the Pear::MDB2 package : http://pear.php.net/package/MDB2/redirected
the PDO Class : http://php.net/manual/en/ref.pdo.php
Leave a Comment
Leave a Comment