Friday, June 19, 2009

Tips for the budding PHP developer

The ease of learning PHP and the trivial deployment of PHP applications (just upload and go) has resulted in everyone’s cousin coding with it and the accompanying impression of being a ‘toy’ language.

The following tips should help the aspiring PHP professional stand out from the crowd:

* Step away from Dreamweaver
To write PHP code efficiently, you need an IDE designed for PHP. If most of your work is with HTML and CSS, you won’t find a better editor than Dreamweaver but if you primarily write PHP code, a PHP editor with features like real time error detection, source control integration, code completion, refactoring support, debugging and built-in unit testing helps big time.
After using Zend Studio for a while now, I am a convert and the version 6.1 is really awesome.

* Get Certified
Writing the PHP certification exam forces you to read up on stuff you my not have come across in your day to day programming. The increased your employability is also a very welcome side effect.

* Use version control
You can thank me later – specifically when your client calls you up at 9 o’clock in the evening to tell you he’s overwritten some of the files you uploaded to his server.
Git is the current version control golden boy but I’ve found Subversion to be stable and effective. Online version control services (e.g. Springloops, Github, CVSDude and Beanstalk) have also reduced the barrier to entry and there’s now to excuse not to do source control.

* Develop locally
Repeat after me – ‘I will not edit code on the production server’. It is essential to have a webserver running on your development machine. All code can be tested rigorously before being deployed to the production server (from the source control repository, obviously). WampServer and Xampp for Windows and Mamp for the Mac take the stress off setting up a local web server. Use one of them.
News Flash! – You don’t have to use Windows. Using a desktop Linux flavour (my choice is Ubuntu) gives you an environment as close as possible to your production server (assuming the PHP installation is on a Linux server – most are) and setting up webservers, virtual hosts and the like on these systems is also a lot easier (due partially to the massive amount of information on the internet).

* Don’t just write it, learn it
It’s amazing how much you can still learn even after working with PHP for years. Programming involves continuously updating your knowledge and skill-set and online resources and books should feature in your everyday work life. The PHP manual and Google are your friends.

* Learn a web framework
A web framework will speed up your code. Common plumbing tasks are already included and you just need to write code specific to your application. Choose one and learn it well.
Which to choose? It depends. For the programmer just getting into OOP and frameworks, CodeIgniter is the easiest to learn but the rigidity of the CakePHP framework may also appeal. My personal preference is a combination of CodeIgniter and the Zend Framework.

* Comment your code
The guy who gets to maintain your code after you will find you and hit you over the head with a big stick if you don’t comment your code. Coming back to your code after a while, chances are you won’t understand what some of the code you wrote is supposed to do.
That said, most of the comments I write adhere to the PHP Documentor standard and I try not to add comments within method blocks but rely on the doc blocks to show intent (thus avoiding the issue of stale comments – changing implementation code and ‘forgetting’ to change the comments). This also has the side effect of forcing me to keep my methods focused, which is good.

* Test Drive your code
You need to do unit testing. Test Driven Development gives you a safety harness when making changes to already working code and a criteria for certifying a piece of code as working.
PHPUnit and SimpleTest are most commonly used for PHP unit testing.

Source : http://avnetlabs.com/php/tips-for-the-budding-php-developer

No comments:

Post a Comment