The SitePoint PHP blog has a new tutorial posted that introduces the idea of "Poka Yoke" - basically defensive programming - and how to apply it in your own development processes.
When working in a medium to large team on the same codebase, it can sometimes become hard to understand each other’s code and how to use it. [...] It can be quite hard to remember how particular classes were intended to work, both on their own and in combination with each other. At that point, it becomes easy to accidentally introduce side effects or bugs without realizing it.
These mistakes might get caught in quality assurance, but there’s a realistic chance they might slip through. And even if they get caught, it can take a lot of time to send the code back and get it fixed. So how can we prevent this? Enter “Poka Yoke”.
The article then introduces the basic ideas of "poka yoke" and the two main parts: mistake prevention and mistake detection. It then gets more practical and suggests some PHP-specific things that can be done to prevent mistakes such as:
- the use of type declarations
- using value objects
- making use of effective validation
- returning null objects
For each there's a brief explaination and some sample code to help make the example more practical.