PHP Best Practices
this page is draft under construction
Agile
Release quickly in short intervals, only what's required now, and be open to changes.
See Agile Manifesto, Scrum.
Coding standards
Adopt consistent coding standards.
Some examples:
It's not really so much important which one you use or whether you use mix of them or even your own. Just be consistnet in your choice.
Documentation
PHPDoc syntax - great for inline documentation as well as generating API reference.
Testing
PHPUnit is leading PHP testing framework.
Advantages :
- warranty that changes or fixes you make don't introduce new bugs somewhere else in your code
- usually you can easily change the internals of your implementation without breaking existing API
- it forces you to write more flexible and modular code
- tests are a sort of documention showing how code actually works and how it should be used
- it forces you to empirically consider how code should behave as well as what possible inputs and corresponding results should be, all that before you start implementation
Refactoring
According to Jason E. Sweat refactoring is the practice of examining all of your code, looking for commonalities and similarities that can be unified and simplified to make the code easier to maintain and extend.
Steps in refactoring:
- Identify the code that can simplified, generalized, made more readable, faster or more secure
- Write tests for the code
- Introduce changes in small steps (running tests after each step)
Revision control
Use version control system. Currently most widely used is Subversion (SVN), which is meant to be replacement for CVS. There is also somewhat more revision control software available.
Reference
- Jason E. Sweat, PHP|Architect's Guide to PHP Design Patterns, Marco Tabini & Associates, Inc. 2005
Last modified: 2008/08/06 19:19 by Przemek Sobstel